[关闭]
@aloxc 2017-12-05T06:36:36.000000Z 字数 1670 阅读 526

ignite中service总结

ignite rpc service


本文基于官方1.7版本给的示例代码

关于部署,示例代码ServicesExample中有如下注释


Example that demonstrates how to deploy distributed services in Ignite.
Distributed services are especially useful when deploying singletons on the ignite,
be that cluster-singleton, or per-node-singleton, etc...

To start remote nodes, you must run {@link ExampleNodeStartup} in another JVM which will start node with {@code examples/config/example-ignite.xml} configuration.

NOTE:
Starting {@code ignite.sh} directly will not work, as distributed services cannot be peer-deployed and classes must be on the classpath for every node. *** 注意最后的一句话,**Starting {@code ignite.sh} directly will not work, as distributed services cannot be peer-deployed and classes must be on the classpath for every node.** 中文意思是说:直接启动ignite服务是无法工作的,因为分布式services不能使用peer-deployed,必须把classes放到每个节点的classpath中去(也可以打jar包)。 一般分布式服务通常是这样的架构,服务端--客户端。其中服务器部署具体的逻辑,客户端连接到服务端,服务端执行一些逻辑然后把结果返回(可能不需要返回)给客户端。 通过阅读示例代码看到,客户端(ServicesExample中)需要指定一些部署相关的信息, 其中这些信息中需要指定服务端的接口实现类,

  1. IgniteServices svcs = ignite.services(ignite.cluster().forRemotes());
  2. // Deploy cluster singleton.
  3. svcs.deployClusterSingleton("myClusterSingletonService", new SimpleMapServiceImpl());
  4. // Deploy node singleton.
  5. svcs.deployNodeSingleton("myNodeSingletonService", new SimpleMapServiceImpl());
  6. // Deploy 2 instances, regardless of number nodes.
  7. svcs.deployMultiple("myMultiService",new SimpleMapServiceImpl(),2 ,0);

那么问题来了,客户端指定服务端的接口实现类,这个感觉有点逻辑问题,都作为客户端了还需要指定服务端的实现,那不就是客户的也需要包含服务端的实现类。
本人接触过几个rpc框架,比如ice、dubbo等,客户端只有一个接口类。实现类应该是放到服务端才对,客户端不应该包含实现类,这样的逻辑应该才正确的。我猜这个问题应该是由于ignite客户端把本地配置成服务端的一部分导致的(本人臆断)。

通过本人的测试,我们可以做下变通处理。服务端的实现类包含完整的逻辑代码,而客户端的实现类只需要实现接口然后方法体中不用包含任何代码。

注意写的这些基于一个这样的配置,指定集群为远程节点,不包含客户端节点
IgniteServices svcs = ignite.services(ignite.cluster().forRemotes());

x

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注