为什么zeroc ice spring没有火起来

c++ - ZeroC ICE vs 0MQ/ZeroMQ vs Crossroads IO vs Open Source DDS - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
How does ZeroC ICE compare to 0MQ? I know that 0MQ/Crossroads and DDS are very similar, but cant seem to figure out where ICE comes in.
I need to quickly implement a system that offloads real-time market-data from C++ to C#, as a first phase of my project. The next phase will be to implement an Event Based architecture with an underlying Pub/Sub design.
I am willing to use TCP.. but the the system is currently running on a single
24 core server.. so an IPC option would be nice. From what I understand ICE is only TCP, while DDS and 0mq have an IPC option.
Currently ,I am leaning towards using Protobuf with either ICE or Crossroads IO. Got turned off from the OpenSplice DDS website. Ive done lots research on the various options, was originally considering OpenMPI + boost:mpi, but there does not seem to be MPI for .NET.
My question is:
How does ICE compare to 0MQ? I cant wrap my head around this. Was unable to find anything online that compares the two.
thanks in advance.
More about my project:
Currently using CMAKE C++ on Windows, but the plan is to move to CentOS at some point. An additional desired feature is to store the tic data and all the messages in a "NoSql" database such as Hbase/Hadoop or HDF5. Do any of these middleware/messaging/pub-sub libraries have any database integration?
If you want real good performance and the only job for Phase 1 of your job is to move data from C++ to C#, then Zmq is the best option.
Having a pub/sub model for event driven architecture is also something that Zmq can help
you with, with its in-built messaging pattern.
Zmq also supports your IPC requirements in this case. Eg: you can have one instance of your application that consumes 24 cores by multithreading and communicating via IPC.
ZeroC Ice:
Ice is a RPC framework very much like CORBA.
Socket/ZMQ - You send message over the wire. Read it at the other end, parse the message, do some action, etc.
ZeroC Ice - Create a contract between client and server. Contract is nothing but a template of a class. Now the client calls a proxy method of that class, and the server implements/actions it and returns the value. Thus, int result = mathClass.Add(10,20) is what the client calls. The method, parameters, etc is marshalled and sent to the server, server implements the Add method, returns the result, and the client gets 30 as the result. Thus on the client side, the api is nothing but a proxy for a servant running on a remote host.
Conclusion:
ZeroC ICE has some nice enterprisy features which are really good. However, for your project requirements, ZMQ is the right tool.
Hope this helps.
Some thoughts about ZeroC:
V Able to hav Able to load bala Able to reconnect to a different endpoint in case one of the node goes down. This is transpa Has good tool chain (IceGrid, IceStorm, IceBox, etc); Distributed, high availability, multiple failover, etc
Apart from that, I have used it for hot swapping code modules (something similar to Erlang) by having the client create the proxy with multiple endpoints, and later on bring down each endpoint for a quick upgrade one by one. With the transparent retry to a different endpoint, I could have the system up and running the whole time i did an upgrade. Not sure if this is an advertised feature or an unadvertised side-effect :)
Overall, it is very easy to scale out your servers if need be using ZeroC Ice.
I know ZeroMQ provides a fantastic set of tools and messaging patterns and I would keep using it for my pet projects. However, The problem that i see is that it is very easy to go overboard and lose track of all your distributed components. This is a must have in a distributed environment. How will you know where your clients/server are when you need to upgrade? If one of components down the chain does not receive a message, how to identify where the issue is? the publisher? the client? or any one of the bridges (REP/REQ, XREP/XREQ, etc) in between?
Overall, ZeroC provides a much better toolset and ecosystem for enterprise solutions.
And it is open source :)
For me.. the correct answer was Crossroads I/O . It does everything I need.. but still unable to
pub/sub when using protobufs... im sure ZeroC ICE is great for distributed IPC, but 0MQ/Crossroads, gives you the added flexibility to use Inter-Thread-Communication.
Note: on windows, 0mq does not have IPC.
So, all in all, the crossroads fork of 0mq is the best. but you will have to roll your own windows/ipc (or use tcp::127..) , and publisher side topic filtering features for pub/sub.
nanomsg, from the guy who wrote crossroads and 0mq (i think).
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled3587人阅读
分布式程序设计(2)
云计算(4)
网络知识(9)
转载请注明原创地址:http://blog.csdn.net/iflychenyang/article/details/8900263
1.首先当然是下载和安装
分别下载了&,&和
依次进行了安装;
2.配置环境变量,这个时候文件被安装到了C:\Program&Files\ZeroC\Ice-3.4.2\目录下,就是在我的电脑中配置环境变量,
计算机-&属性-&高级系统设置-&环境变量-&系统变量-&Path中进行添加“;C:\Program&Files\ZeroC\Ice-3.4.2\bin\vc100”
这个时候应该就可以在命令行环境下进行测试了
slice2cpp -v
得到的结果应该是
3.新建项目
client和server,如下图所示
4.配置工程依赖项
点击状态栏:Tools-&Ice Configuration...,选择Enale Ice Builder,如下图所示:
我们接下来讲的一些都是配置好ICE的基础上实现的。
5.打开VS2010,新建一个项目,命名为“server”,在源文件处添加 新建项,这个时候“已安装的模板”的最下方为“Slice”, 选中它,添加Slice File(.ice) 命名为Printer.ice,内容为:
module Demo{
interface Printer{
void printString(string s);
6.编译此ice文件,我采用的办法是到对应的目录下,使用命令行来进行编译,编译命令也就是slice2cpp Printer.经过编译,我们得到两个文件Printer.h和Printer.cpp,将这两个文件作为现有项添加到Server项目中,
7.添加一个新的Server.cpp文件,内容是参照Ice 3.4.2的设计文档得到的:
#include &Ice/Ice.h&
#include &Printer.h&
#include &iostream&
using namespace D
class PrinterI : public Printer
virtual void printString(const string &s, const Ice::Current &);
void PrinterI ::printString(const string & s, const Ice::Current &)
int main(int argc, char * argv[])
int status = 0;
Ice::CommunicatorP
ic = Ice::initialize(argc,argv);
Ice::ObjectAdapterPtr adapter
= ic-&createObjectAdapterWithEndpoints(&SimplePrinterAdapter&,&default -p 10000&);
Ice::ObjectPtr object = new PrinterI;
adapter-&add(object,ic-&stringToIdentity(&SimplePrinter&));
adapter-&activate();
ic-&waitForShutdown();
}catch (const Ice::Exception & e)
status = 1;
catch (const char * msg)
cerr&&msg&&
status = 1;
ic-&destroy();
catch(const Ice::Exception & e)
status = 1;
8.这里有个小问题需要注意一下,就是原文中使用的是&#include&Printer.h&&,应该改用双引号#include&Printer.h&,原因可能是&&到系统指定的一些目录中查找文件,但是“”找的范围更大些。
9.编译此项目,我在第一次编译的时候出了很多问题,原因就是忘了添加附加依赖项,也就出了很多链接无法解析的问题,将iced.lib和iceutild.lib添加进去后,就没有了这些问题。
上面的工作主要用于完成服务器端的任务,而剩下的就是客户端的任务了,
10.首先还是新建一个项目,命名为Client
11.当然其次还是要配置项目的环境属性
12.我在这还是将Server项目下的Printer.h和Printer.cpp复制进了这个新的项目中,而且只复制Printer.h也是有问题的,会出现很多链接无法解析
13.添加Client.cpp文件,内容如下:#include&Ice/Ice.h&
#include &Printer.h&
#include &iostream&
#include &string&
using namespace D
int main(int argc, char * argv[])
int status = 0;
Ice::CommunicatorP
ic = Ice::initialize(argc,argv);
Ice::ObjectPrx base = ic-&stringToProxy(&SimplePrinter:default -p 10000&);
PrinterPrx printer = PrinterPrx::checkedCast(base);
if(!printer)
throw &invalid proxy&;
printer-&printString(&Hello World!&);
catch(const Ice::Exception& ex)
cerr&&ex&&
status = 1;
catch (const char* msg)
cerr&&msg&&
status = 1;
ic-&destroy();
14.分别运行server和client
15.Hello World!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:50629次
排名:千里之外
原创:29篇
转载:30篇
(1)(1)(2)(1)(1)(2)(1)(1)(1)(1)(1)(1)(3)(2)(2)(1)(3)(6)(4)(4)(6)(2)(4)(2)(4)(2)ZeroC ICE之旅
Ice 是 Internet Communications Engine 的简称,出自ZeroC名门之下。 Ice 是一种面向对象的中间件平台。从根本上说,这意味着Ice 为构建面向对象的客户-服务器应用提供了工具、API 和库支持。Ice 应用适合于异构平台环境中使用:客户和服务器可以采用不同的编程语言,可以运行在不同的操作系统和机器架构上,并且可以使用多种网络技术进行通信。无论部署环境如何,这些应用的源码都是可移植的。
其采用C/S 模式结构,支持同步调用方式和异步调用方式,异步派发调用方式。支持跨语言的对象调用。多种语言之间采用共同的Slice(Specification Language for Ice)进行沟通。支持ice到C,JAVA,C#,VB,Python,Ruby,PHP等多种语言的映射。
工欲善其事,必先利其器,我们首先从,下载最新安装包; btw:
目前最新的v3.3 /download_beta.html 最新稳定版本: /download.html
由于我自己的平台是CentOS release 4.4 (Final),java version "1.6.0_01" 所以下载的是: /download/Ice/3.3/Ice-3.3b-rhel4-i386-rpm.tar.gz
解开之后: -rw-r--r--1 506 users
10:39 db46-4.6.21-2ice.rhel4.i386.rpm -rw-r--r--1 506 users 10:39 db46-devel-4.6.21-2ice.rhel4.i386.rpm -rw-r--r--1 506 users 10:40 db46-java-4.6.21-2ice.rhel4.i386.rpm -rw-r--r--1 506 users 10:40 db46-utils-4.6.21-2ice.rhel4.i386.rpm -rw-r--r--1 506 users 10:15 ice-3.3b-1.rhel4.noarch.rpm -rw-r--r--1 506 users 10:15 ice-c++-devel-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users
10:16 ice-java-3.3b-1.rhel4.noarch.rpm -rw-r--r--1 506 users 10:16 ice-java-devel-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users
10:17 ice-libs-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:19 ice-php-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:19 ice-python-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:19 ice-python-devel-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:19 ice-ruby-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:19 ice-ruby-devel-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users
10:20 ice-servers-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users
10:24 ice-utils-3.3b-1.rhel4.i386.rpm -rw-r--r--1 506 users 10:40 mcpp-devel-2.6.4-1ice.rhel4.i386.rpm 由于需要c和java的包: 所以我们仅安装: rmp -ivh ice-3.3b-1.rhel4.noarch.rpm rmp -ivh ice-3.3b-1.rhel4.noarch.rpm rpm -ivh ice-3.3b-1.rhel4.noarch.rpm rpm -ivh ice-libs-3.3b-1.rhel4.i386.rpm rpm -ivh ice-utils-3.3b-1.rhel4.i386.rpm rpm -ivh mcpp-devel-2.6.4-1ice.rhel4.i386.rpm rpm -ivh ice-servers-3.3b-1.rhel4.i386.rpm rpm -ivh ice-libs-3.3b-1.rhel4.i386.rpm rpm -ivh ice-c++-devel-3.3b-1.rhel4.i386.rpm rpm -ivh ice-java-3.3b-1.rhel4.noarch.rpm rpm -ivh ice-java-devel-3.3b-1.rhel4.i386.rpm
安装之后的Ice相关路径: slice2cpp,slice2java在/usr/bin/下 Ice.jar 存储于 /usr/share/java/下 相关的Ice的库存储于/usr/lib下.
一切就绪,我们开始Ice之旅的Slice地带: 首先,我们建立一个demo.ice的文件:
moduleDemo{
interfacetest{
stringexecute(stringmth,stringcmd);
注意,后两个"}"一定要包含";",否则slice2java就会过不去,赫赫
slice2java demo.ice
会在当前目录产生一个Demo目录,目录下自动生成:
-rw-r--r--1 root root 23164月 15 17:01 _testDelD.java
-rw-r--r--1 root root5604月 15 17:01 _testDel.java
-rw-r--r--1 root root 19294月 15 17:01 _testDelM.java
-rw-r--r--1 root root 41774月 15 17:01 _testDisp.java
-rw-r--r--1 root root 10704月 15 17:01 testHolder.java
-rw-r--r--1 root root4884月 15 17:01 test.java
-rw-r--r--1 root root4814月 15 17:01 _testOperations.java
-rw-r--r--1 root root4604月 15 17:01 _testOperationsNC.java
-rw-r--r--1 root root 54184月 15 17:01 testPrxHelper.java
-rw-r--r--1 root root5694月 15 17:01 testPrxHolder.java
-rw-r--r--1 root root5674月 15 17:01 testPrx.java
到目前为止,demo.ice所以Ice接口部分的定义以及相关依赖都已经自动生成.
我们要实现自己的execute方法,覆盖testPrx.java的同名方法:
//TestImp.java
importIce.C
publicclassTestImpextends_testDisp{
publicStringexecute(Stringmth,Stringcmd,Current__current){
//TODOAuto-generatedmethodstub
returnmth+
看到了,就是这么简单,仅仅覆盖_testDisp里面的抽象方法,实现把我们自己的实现代码填充到里面就行了.
之后,我们建立一个Server服务在10000端口进行侦听。
//Server.java
publicclassServer{
publicstaticvoidmain(String[]args){
intstatus=0;
municatoric=
ic=Ice.Util.initialize(args);
Ice.ObjectAdapteradapter=ic.createObjectAdapterWithEndpoints(
"TestAdapter","default-p10000");
Ice.Objectobject=newTestImp();
adapter.add(object,ic.stringToIdentity("TestAdapter"));
adapter.activate();
ic.waitForShutdown();
}catch(Ice.LocalExceptione){
e.printStackTrace();
}catch(Exceptione){
System.err.println(e.getMessage());
if(ic!=null){
ic.destroy();
}catch(Exceptione){
System.err.println(e.getMessage());
System.exit(status);
貌似很复杂,其实里面的很多内容都是固定格式,有些部分需要固定和约定。其中上述红色部分是修改部分。
到目前为止,我们已经完成了大部分工作,我们还需要建一个客户端来对服务端的方法进行调用。
publicclassClient{
publicstaticvoidmain(String[]args){
intstatus=0;
municatoric=
ic=Ice.Util.initialize(args);
//Ice.ObjectPrxbase=ic
//.stringToProxy("SimplePrinter:tcp-h172.17.12.101-p10000");
Ice.ObjectPrxbase=ic
.stringToProxy("TestAdapter:default-p10000");
testPrxtest=testPrxHelper.checkedCast(base);
if(test==null)
thrownewError("Invalidproxy");
System.out.println(test.execute("MyfirstIce","demo"));
//System.out.println("ok");
}catch(Ice.LocalExceptione){
e.printStackTrace();
}catch(Exceptione){
System.err.println(e.getMessage());
if(ic!=null){
ic.destroy();
}catch(Exceptione){
System.err.println(e.getMessage());
System.exit(status);
也貌似很复杂吧,其实不然,也很简单,同样包含很多固定格式。其中
System.out.println(test.execute("myfirstIce","demo"));
是我们自己调用的逻辑。
赫赫,大功告成了,现在我们开始运行Server,再运行Client看到了么?
"My first Ice demo"
得到这样的结果,基本Ice之旅的Java部分简单实例我们基本完成。
Ice的性能和稳定性远超于我们的想象,skype知道么?其部分通讯架构就是采用的Ice.
ZeroC ICE之旅------Slice
Slice是在ICE所特有的特殊语言,ICE 提供基于Ice语言的多语言映射工具。Slice主要针对程序所涉及到的接口和类型进行定义。不涉及到具体实现和具体语言的特征。 既然ICE支持跨语言的调用,那么是不是Slice支持每种的特有数据类型呢? 当然不是,ICE只是保留各种具体语言数据类型的最小交集。 提供:
1.bool(falseortrue,>=1bit)
2.byte(-128-127@,>=8bits)
3.short(-2^15to2^15-1,>=16bits)
4.int(-2^31to2^31-1,>=32bits)
5.long(-2^63to2^63-1,>=64bits)
6.float(IEEEsingle-precision,>=32bits)
7.double(IEEEdouble-precision,>=64bits)
8.string(AllUnicodecharacters,excluding,thecharacterwithallbitszero.)
string 采用Unicode编码,具有很好的国际化语言支持。
下面主要在介绍一下Slice的特性和约束:
1. Slice文件必须以.ice结尾,其他结尾方案的文件会被编译器拒绝。
2. Slice 文件格式实际就是text文本描述,由于Slice形式自由,可以用任何文本编辑器进行编辑。
3. Slice 支持#ifndef,#define,#endif,#include
//FileClock.ice
#ifndef_CLOCK_ICE
#define_CLOCK_ICE
//#includedirectiveshere...
//Definitionshere...
#endif_CLOCK_ICE
在include 要避免使用双引号"",以及"",而要使用"/"
#include "Clock.ice" // 不推荐采用;
4.Slice 中文件的结构,模块,接口,类型出现的顺序,,可以按照你的喜好而自由定义。
5.Slice 的词法规则很多来源于C++和Java,只有少量的差异。
6.可以采用c++的注释规则。// 或
7.Slice 的关键词需要区分大小写:
boolenumimplementsmodulestruct
byteexceptionintObjectthrows
classextendsinterfaceouttrue
constfalselocalsequencevoid
dictionaryfloatLocalObjectshort
doubleidempotentlongstring
8.在接口定义的时候也避免使用非Slice关键字,但是C++ 或 Java关键字的标识符。
例如:switch
9.Ice保留了所有以"ice"作为开始标识符。保留以"Helper","Holder","Prx","Ptr"结尾的标识符。所以大家定义的时候最好避免一些不必要的麻烦。
10.Ice可以通过module嵌套的方式,类似于c++的namespace和java的包的概念。
11.除了刚才提到的Slice支持的基础类型外,还支持用户自定义类型:enumerations, structures, sequences, and dictionaries.
enumerations:枚举就不要介绍了,采用C++的语法形式
enum Fruit { Apple, Pear, Orange };
Structures:结构,也是采用C++的语法形式,避免,结构中定义结构
structTimeOfDay{
structTwoPoints{
structPoint{//Illegal!
Pointcoord1;
Pointcoord2;
sequence:序列号类型,映射到java采用的数组方式实现,而不是所谓的集合容器类型对象存储。映射到C++中则采用STL容器存储。
dictionary:字典类型,映射到java采用Map 进行存储,映射到C++采用map进行存储.
dictionary myV
12.常量定义可以直接使用,但常量的定义必须是基本类型或枚举类型.定义形式也是采用C++定义方式.
13.方法的定义,形式类型java的方法定义,方法返回可以使void或对象类型.
14.Slice支持方法异常的定义,以及异常的继承.关于异常机制,我想java开发者可能更加熟悉,
exceptionError{};//Emptyexceptionsarelegal
exceptionRangeError{
TimeOfDayerrorT
TimeOfDayminT
TimeOfDaymaxT
interfaceClock{
idempotentTimeOfDaygetTime();
idempotentvoidsetTime(TimeOfDaytime)
throwsRangeError,E
Ice的错误机制也是异常强大,吸取了很多Java关于异常机制的特点.
Slice还包括很多良好的特性,在这里就不一一列举,对于支持自定义类型,基本类型,异常支持,对于一般的网络通讯应用已经足够了,更多Slice语言的介绍参阅其帮助.
Ice为我们提供了强大而又丰富的Slice,可以利用Slice,结合我们应用的特点,定义间接的Slice描述。
虽然Slice提供给我们丰富的功能和特性,在此我还是建议大家尽量采用基本类型和非异常机制.这样会对系统性能会带有一定的帮助。
另外接口的定义我想大家能够保持KISS(Keep it It Simple)设计原则,会使我们的应用看起来更美丽。
不要过度的使用Slice,否则会给我们带来无尽的烦恼。
ZeroC ICE之旅------多语言互通互联
ce的服务端可以采用C++/Java/Python/C#等实现,客户端可以采用C++/Java/Python/C#/VB/PHP/Ruby来实现,就是说我的一个服务端采用C++实现,客户端可以采用java/php/vb/c# 等其他语言实现。
这个特性也是Ice的很重要的优势之一.
Ice的多语言之间如何确保对象的正确传输,每种语言都有各自的特点,数据类型,Ice是如何达到各种语言之间的互通互联的呢? 那么就一定提到Slice语言.Slice是保证各种语言的互通互联的关键,它是独立于其它任何语言,Ice可以通过把Slice代码片断转化为各自的
-rwxr-xr-x1systemusers-03-09slice2java
-rwxr-xr-x1systemusers-09slice2py
-rwxr-xr-x1systemusers-09slice2rb
-rwxr-xr-x1systemusers-03-09slice2vb
-rwxr-xr-x1systemusers-03-09slice2cpp
-rwxr-xr-x1systemusers-03-09slice2cs
赫赫够多!
Slice的全称:Specification Language for Ice,是Ice自己的特殊语言,一种用于使对象接口与其实现相分离的基础性抽象机制。Slice 建立在客户与服务器之间的合约,用以描述应用所使用的类型和对象接口。Slice描述独立于实现语言,所以客户实现语言是否与编写服务器所用的语言相同没有任何关系。
slice语言片段可以被编译为任何所支持语言的实现。目前Ice Slice可以支持映射到到C++, Java, C#, Python,Ruby, and PHP。
因为Slice主要对接口和类型的定义和描述,没有实现部分。
到底如何实现不同语言的互通互联的呢?我们已Java,C++作为Ice例子原形,实际上我们仅仅做少量修改,就可以实现
C++的服务端,Java的客户端。Server和Client还是保持在同一台机器上运行。注意我们基于同一个demo.ice的事例。
首先运行./Server,再运行Client,看到结果了么?赫赫,是不是出现了正常结果。
到目前没有我们所有实例都是基于同一台机器的,实际情况Server,Client会分布在不同机器上。这种情况下,我们需要如何处理呢?
这个很简单,在Server少量修改
Ice::ObjectAdapterPtradapter=ic->createObjectAdapterWithEndpoints("TestAdapter","default-p10000");
"default -p 10000" 采用 "tcp -h server1 -p port" 替代
Server所在主机IP:172.17.12.101 ,端口:10000
所以就修改为:tcp -h 172.17.12.101 -p 10000,再重新编译Server
usingnamespaceD
classServer:publictest
::std::stringexecute(conststring&mth,conststring&str,
constIce::Current&);
Server::Server()
std::stringServer::execute(conststring&mth,conststring&str,
constIce::Current&)
cout<<mth+str<<
returnmth+
main(intargc,char*argv[])
Ice::CommunicatorP
ic=Ice::initialize(argc,argv);
Ice::ObjectAdapterPtradapter
ic->createObjectAdapterWithEndpoints("TestAdapter",
"tcp-h172.17.12.101-p10000");
Ice::ObjectPtrobject=newS
adapter->add(object,ic->stringToIdentity("TestAdapter"));
adapter->activate();
ic->waitForShutdown();
}catch(constIce::Exception&e)
}catch(constchar*msg)
cerr<<msg<<
ic->destroy();
catch(constIce::Exception&e)
编译方式参见:
/blog/183307
下面我们需要对Client连接部分进行修改,同理:
Ice.ObjectPrxbase=ic.stringToProxy("TestAdapter:tcp-h172.17.12.101-p10000");
publicclassClient{
publicstaticvoidmain(String[]args){
intstatus=0;
municatoric=
ic=Ice.Util.initialize(args);
//Ice.ObjectPrxbase=ic
//.stringToProxy("SimplePrinter:tcp-h172.17.12.101-p10000");
Ice.ObjectPrxbase=ic
.stringToProxy("TestAdapter:tcp-h172.17.12.101-p10000");
testPrxtest=testPrxHelper.checkedCast(base);
if(test==null)
thrownewError("Invalidproxy");
System.out.println(test.execute("MyfirstIce","事例"));
//System.out.println("ok");
}catch(Ice.LocalExceptione){
e.printStackTrace();
}catch(Exceptione){
System.err.println(e.getMessage());
if(ic!=null){
ic.destroy();
}catch(Exceptione){
System.err.println(e.getMessage());
System.exit(status);
看到了么,就是这么简单,其他部分不用修改。
好了,我们进行验证,首先启动./Server,再执行Client ,看到了
"My first Ice 事例" 看到了么,祝贺你,跨语言的分布式调用例子你已经实现了。
其实Ice的通讯机制极其强大,支持集群和容错技术。关于集群的事例会在日后的文章中介绍。
注意,Server运行之后监听于10000端口,需要修改iptables,允许其他机器可以连接。
编辑 iptables
vi /etc/sysconfig/iptables
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport10000-jACCEPT
ZeroC ICE之旅------负载均衡及容错
Zero ICE我们已经掌握其基本运行原理。下面我们主要介绍一下ICe的多端口邦定的问题。 ICE使用TCP/IP 和UDP协议,以及基于TCP/IP之上的SSL协议。SSL协议可以充分保障Server/Client数据传输的加密安全性问题。 在这里,Server如何在同一台主机监听多个端口。
关于TCP/IP还是UDP还是SSL协议的选择,还是要看具有应用的要求,通常情况下TCP/IP协议的ICE应用已经足够了。
在同一个主机主机上,ICE服务支持多端口的监听。
服务端注册: tcp -h host -p port1:tcp -h host -p port2形式,
IP:172.17.12.101,需要在1同时监听。
就可以写成:
tcp -h 172.17.12.101 -p 10000:tcp -h 172.17.12.101 -p 10001
赫赫是不是很简单,运行之后,服务就监听于1端口,请注意:避免其他应用相冲突。
客户端连接可以采用如下3种形式:
1. tcp -h 172.17.12.101 -p 10000 2. tcp -h 172.17.12.101 -p 10001 3. tcp -h 172.17.12.101 -p 10000:tcp -h 172.17.12.101 -p 100001
是不是很爽。
无论Server监听在多个端口,还是只有唯一的一个Server在工作,
对于Client较多的应用或负载要求很高的情况下,我们可以把Server程序运行于多台主机之上。通过集群方式合理有效的化解来自Client的压力。
ServerA 172.17.12.101 tcp -h 172.17.12.101 -p 10000 ServerB 172.17.12.102 tcp -h 172.17.12.102 -p 10000 ServerC 172.17.12.103 tcp -h 172.17.12.103 -p 10000
Client可以如下的连接方式: tcp -h 172.17.12.101 -p 10000:tcp -h 172.17.12.102 -p 10000:tcp -h 172.17.12.103 -p 10000
或是 tcp -h 172.17.12.101 -p 10000:tcp -h 172.17.12.102 -p 10000
等多种情况,可以根据应用的具体要求合理有效的构造所需连接主机的字符串。
这种连接方式是不是很cool。
其实这种连接方式可以有效地利用ICE提供的load balancing功能,把Client的每个请求合理的分配到每个Server。从而有效地避免了Client大量请求对同一台Server的巨大压力。
ICE的load balancing主要采用round-robin算法,round-robin是一种非常有效的负载均衡算法.
大家会问了,如果某个Server如果宕机,那么这个Client还能正常工作么?
这个问题问得好,其实ICE自身提供一种极其强大容错技术功能。 具体体现在如果当某个Server(假设是ServerA)宕机之后,来自Client的请求分配到ServerA服务器上,Client会自动记录ServerA失效状态,会把请求再分配给可正常工作的Server(ServerB,ServerC),对于用户的每次请求都能分配到正常的服务主机上(除非A,B,C都同时宕机).当ServerA回复正常之后,Client会自动感知ServerA工作状态.Client的请求又可以有效地分配到上述A,B,C主机上.这一切对于开发者都是透明的.
ICE所提供的集群功能和容错功能是极其强大的.
Client状态感知的变化和更新完全不需要Client重新启动。
无相关信息
最新教程周点击榜
微信扫一扫

我要回帖

更多关于 zeroc ice 的文章

 

随机推荐