我們目前使用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,如下所述。 –