我们目前使用vertx和hazelcast作为其群集实现。为了按照文档工作,hazelcast嵌入到我们的应用程序中,意味着它将作为集群的成员加入。我们希望我们的应用程序独立于Hazelcast。原因在于,当Hazelcast缓存变得不一致时,我们会关闭所有服务器并重新启动。相反,我们希望将Hazelcast保留在自己的服务器上,并将vertx作为客户端连接,以便我们重新启动与我们的应用程序服务器无关的hazelcast。 Zookeeper集群实现完全符合我们的需求,但我们不希望为此目的维护另一个集群,因为我们也将Hazelcast用于其他缓存目的,这些目的是在我们的应用程序内部。目前我们正在做一些这样的事情来使vertx工作。Hazelcast可以作为客户端连接到现有的Hazelcast群集,而不是作为群集的成员加入以实现vertx群集
Config hazelcastConfig = new Config();
//Group
GroupConfig groupConfig = new GroupConfig();
groupConfig.setName(hzGroupName);
groupConfig.setPassword(groupPassword);
hazelcastConfig.setGroupConfig(groupConfig);
//Properties
Properties properties = new Properties();
properties.setProperty("hazelcast.mancenter.enabled", "false");
properties.setProperty("hazelcast.memcache.enabled", "false");
properties.setProperty("hazelcast.rest.enabled", "false");
properties.setProperty("hazelcast.wait.seconds.before.join", "0");
properties.setProperty("hazelcast.logging.type", "jdk");
hazelcastConfig.setProperties(properties);
//Network
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.setPort(networkPort);
networkConfig.setPortAutoIncrement(networkPortAutoincrement);
//Interfaces
InterfacesConfig interfacesConfig = new InterfacesConfig();
interfacesConfig.setEnabled(true);
interfacesConfig.setInterfaces(interfaces);
networkConfig.setInterfaces(interfacesConfig);
//Join
JoinConfig joinConfig = new JoinConfig();
MulticastConfig multicastConfig = new MulticastConfig();
multicastConfig.setEnabled(false);
joinConfig.setMulticastConfig(multicastConfig);
TcpIpConfig tcpIpConfig = new TcpIpConfig();
tcpIpConfig.setEnabled(true);
List<String> members = Arrays.asList(hzNetworkMembers.split(","));
tcpIpConfig.setMembers(members);
joinConfig.setTcpIpConfig(tcpIpConfig);
networkConfig.setJoin(joinConfig);
//Finish Network
hazelcastConfig.setNetworkConfig(networkConfig);
clusterManager = new HazelcastClusterManager(hazelcastConfig);
VertxOptions options = new VertxOptions().setClusterManager(clusterManager);
options.setClusterHost(interfaces.get(0));
options.setMaxWorkerExecuteTime(VertxOptions.DEFAULT_MAX_WORKER_EXECUTE_TIME * workerVerticleMaxExecutionTime);
options.setBlockedThreadCheckInterval(1000 * 60 * 60);
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
vertx = res.result();
} else {
throw new RuntimeException("Unable to launch Vert.x");
}
});
*********替代的解决方案**********
我们实际上改变了我们的分布式缓存实现从hazelcast到Redis的(亚马逊ElastiCache)。
我们之所以选择依靠榛树有三个原因。
1)因为它在服务器重启过程中的不一致性
2)我们使用的是嵌入式hazelcast,当榛树数据不一致时我们最终重新启动了我们的应用程序,我们希望我们的应用程序独立于其他服务
3)内存分配(hazelcast数据)现在独立于应用程序服务器
我已添加备用解决方案以发布我们最终做的 – Mallikarjun
我认为我的答案在下面解决了您的问题1,2和3.但您必须等待测试拉取请求解决(或做你自己的'vertx-hazelcast'结节)。很高兴听到它在人们活动案例中的效果如何。 –
Vert.x已经发布了3.2.1,并在我的回答中提到了拉取请求,现在您可以使用Hazelcast Smart Clients,如下所述。 –