ICE提纲之demo/IceStorm/clock

ICE发布者/订阅者的一个最简单例子

IceStorm服务

config.icebox

#
# The IceBox server endpoint configuration. This endpoint is only used
# to communicate with the IceBox ServiceManager object (such as when
# using iceboxadmin to shutdown the server).
#
# The IceStorm service has its own endpoints (see config.service).
#
IceBox.ServiceManager.Endpoints=tcp -h localhost -p 9998

#
# The IceStorm service. The service is configured using a separate
# configuration file (see config.service).
#
IceBox.Service.IceStorm=IceStormService,35:createIceStorm --Ice.Config=config.service

config.service

#
# The IceStorm service instance name.
#
IceStorm.InstanceName=DemoIceStorm

#
# This property defines the endpoints on which the IceStorm
# TopicManager listens.
#
IceStorm.TopicManager.Endpoints=default -h localhost -p 10000

#
# This property defines the endpoints on which the topic
# publisher objects listen. If you want to federate
# IceStorm instances this must run on a fixed port (or use
# IceGrid).
#
IceStorm.Publish.Endpoints=tcp -h localhost -p 10001:udp -h localhost -p 10001

Slice

Clock.ice

module Demo
{

interface Clock
{
    void tick(string time);
};

};

发布者

config.pub

#
# This property is used by the clients to connect to IceStorm.
#
TopicManager.Proxy=DemoIceStorm/TopicManager:default -h localhost -p 10000

Publisher.cpp

int
Publisher::run(int argc, char* argv[])
{
    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
        communicator()->propertyToProxy("TopicManager.Proxy"));

    //
    // Retrieve the topic.
    //
    string topicName = "time";
    IceStorm::TopicPrx topic;
    topic = manager->create(topicName);
    // or
    topic = manager->retrieve(topicName);

    //
    // Get the topic‘s publisher object, and create a Clock proxy
    //
    Ice::ObjectPrx publisher = topic->getPublisher();

    ClockPrx clock = ClockPrx::uncheckedCast(publisher);

    while(true)
    {
        clock->tick(IceUtil::Time::now().toDateTime());
        IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
    }
}

订阅者

config.sub

#
# This property is used to configure the endpoints of the clock
# subscriber adapter. These endpoints are where the client receives
# topic messages from IceStorm.
#
Clock.Subscriber.Endpoints=tcp:udp

#
# This property is used by the clients to connect to IceStorm.
#
TopicManager.Proxy=DemoIceStorm/TopicManager:default -h localhost -p 10000

Subscriber.cpp

class ClockI : public Clock
{
public:

    virtual void
    tick(const string& time, const Ice::Current&)
    {
        cout << time << endl;
    }
};

int
Subscriber::run(int argc, char* argv[])
{
    string topicName = "time";

    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
        communicator()->propertyToProxy("TopicManager.Proxy"));

    IceStorm::TopicPrx topic;
    topic = manager->retrieve(topicName);
    // or
    topic = manager->create(topicName);

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Clock.Subscriber");

    //
    // Add a servant for the Ice object. If --id is used the identity
    // comes from the command line, otherwise a UUID is used.
    //
    // id is not directly altered since it is used below to detect
    // whether subscribeAndGetPublisher can raise AlreadySubscribed.
    //
    Ice::Identity subId;
    Ice::ObjectPrx subscriber = adapter->add(new ClockI, subId);

    //
    // Activate the object adapter before subscribing.
    //
    adapter->activate();

    IceStorm::QoS qos;
    qos["retryCount"] = retryCount;
    qos["reliability"] = "ordered";

    topic->subscribeAndGetPublisher(qos, subscriber);

    shutdownOnInterrupt();
    communicator()->waitForShutdown();

    topic->unsubscribe(subscriber);
}

ICE提纲之demo/IceStorm/clock

时间: 2024-08-25 04:42:14

ICE提纲之demo/IceStorm/clock的相关文章

ICE提纲之demo/Glacier2/callback

本例子展示了Glacier2 router的用法(没有使用Glacier2 session manager). 如果clients与router不在同一台主机上,需要将以下地方修改为glacier2router所在机器的外部地址: config.glacier2的Glacier2.Client.Endpointsconfig.client的Ice.Default.Router和Callback.Client.Router Glacier2router服务 启动命令 $ glacier2route

ICE中间件介绍以及demo

一:基本开发步骤 根据业务编写slice:写任何ICE应用的第一步都要编写一个slice定义,其中包含了这个应用的所有接口 编写实现接口代码:命名规则就是接口的名字加上I 编写server端代码 写配置文件,部署服务 编写client端代码 先启动server端服务,然后启动client端服务 二:demo(安装ice服务) 定义一个接口,建立一个Printer.ice文件 moudle Demo{     interface Printer{ void printString(string s

ICE安装及使用示例

ICE是什么 ZeroC ICE 是指ZeroC公司的ICE(Internet Communications Engine)中间件平台. Ice 应用适合于异构平台环境中使用:客户和服务器可以采用不同的编程语言,可以运行在不同的操作系统和机器架构上,并且可以使用多种网络技术进行通信.无论部署环境如何,这些应用的源码都是可移植的. 其采用C/S 模式结构,支持同步调用方式和异步调用方式,异步派发调用方式.支持跨语言的对象调用.多种语言之间采用共同的Slice(Specification Langu

ice安装以及简单使用

ICE(Internet Communications Engine)是一个中间件平台.作为一个高性能的互联网通信平台,ICE包含了很多分层的服务和插件(Plug-ins),并且简单.高效和强大. ICE当前支持C++.Java.C#.Visual Basic.Python和PHP编程语言,并支持在多种操作系统上运行.更多的操作系统和编程语言将会在以后的发布中支持. 1:下载安装包:http://www.zeroc.com/download.html 2:安装ice并在环境变量中配置ice的安装

KDevelop

ctags+vim还是太累了,还是使用IDE好,尤其是c++模板.KDevelop就不错,符号智能推导以及cmake项目管理和配置,还是挺好用的. Android端的ndk开发使用Android Studio,服务端开发就用KDevelop,谁让我用了Ice. KDevelop不用编译,不用yum或apt,就连安装rpm或deb也不用,下载来就一个文件直接运行,到官方网下载就可以了. 以编译Ice一个demo为例,浏览一遍使用. 新建一个项目 我们要的就是 simple CMake 然后在终端

实验 1 Java 运行环境的安装、配置与运行

一.实验目的     1. 掌握下载 Java SDK 软件包.     2. 掌握设置 Java 程序运行环境的方法.     3. 掌握编写与运行 Java 程序的方法.     4. 了解 Java 语言的概貌. 5. 安装.掌握JCreator软件,为学习 Java 语言和进行 Java 程序的实验做好准备工作. 6. 浏览Applet 程序 二.实验要求     1. 安装并设置 Java SDK 软件包.     2. 编写一个简单的 Java 程序,在屏幕上输出"hello,jav

STM32 GPIO fast data transfer with DMA

AN2548 -- 使用 STM32F101xx 和 STM32F103xx 的 DMA 控制器 DMA控制器 DMA是AMBA的先进高性能总线(AHB)上的设备,它有2个AHB端口: 一个是从端口,用于配置DMA,另一个是主端口,使得DMA可以在不同的从设备之间传输数据. DMA的作用是在没有Cortex-M3核心的干预下,在后台完成数据传输. 在传输数据的过程中,主处理器可以执行其它任务,只有在整个数据块传输结束后, 需要处理这些数据时才会中断主处理器的操作. 它可以在对系统性能产生较小影响

Lua-Async 协程的高级用法

Lua-Async 这是一个基于协程的异步调用库, 该库的设计思路类似JavaScript的Promise, 但相比Promise, 它有更多的灵活性. -- 引入Async local Async = require("Async") -- 创建Async -- 可传递参数到接下来的调用中 Async.New(...) -- 注册异步调用 Async.New(...) :Ok(function(ok, no, ...) return no() end) -- 在Ok管道注册回调, 之

ice demo

----------------------------------------------转------------------------- 1.ICE是什么? ICE是ZEROC的开源通信协议产品,它的全称是:The Internet Communications Engine,翻译为中文是互联网通信引擎,是一个面向对象的中间件,使我们能够以最小的代价构建分布式应用程序.ICE使我们专注于应用逻辑的开发,它来处理所有底层的网络接口编程,这样我们就不用去考虑这样的细节:打开网络连接.网络数据