我有一个由两个节点组成的淡褐色嵌入式集群。如果我使用HazelcastClient.newHazelcastClient()实例,我可以访问群集中的地图,但如果我使用Hazelcast.newHazelcastInstance(),我将无法获得相同的结果。如果我从一个节点操纵地图,另一个节点在完全不同的地图上工作;变化不存在。
是否要求我应该使用HazelcastClient实例连接到嵌入式hazelcast集群。当您拥有实际的集群实例对象时,似乎没有必要在嵌入模式下创建和配置客户端(hazelcast-client.xml)。
编辑: - 使用的发现机制是TCP。
下面显示的安装程序有两个简单的java WAR文件,它们运行在同一台机器上运行的两个不同的tomcats上。我通过TCP发现机制使它们可被发现,如下所示。
hazelcast.xml(仅限顶部)
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.9.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>dev</name>
<password>dev-pass</password>
</group>
<management-center enabled="false">http://localhost:8080/mancenter</management-center>
<properties>
<property name="hazelcast.discovery.enabled">true</property>
</properties>
<network>
<port auto-increment="true" port-count="100">5701</port>
<outbound-ports>
<ports>5700-6750</ports>
</outbound-ports>
<join>
<multicast enabled="false">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled="true">
<member-list>
<member>127.0.0.1:5701</member>
<member>127.0.0.1:5702</member>
</member-list>
</tcp-ip>
日志输出(来自节点1)
STARTING UP INSTANCE...
Apr 09, 2018 5:26:40 PM com.hazelcast.config.XmlConfigLocator
INFO: Loading 'hazelcast.xml' from classpath.
Apr 09, 2018 5:26:40 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.9.3] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [127.0.0.1]
Apr 09, 2018 5:26:40 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.9.3] Picked [127.0.0.1]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Apr 09, 2018 5:26:40 PM com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Hazelcast 3.9.3 (20180216 - 539b124) starting at [127.0.0.1]:5701
Apr 09, 2018 5:26:40 PM com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
Apr 09, 2018 5:26:40 PM com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Configured Hazelcast Serialization version: 1
Apr 09, 2018 5:26:40 PM com.hazelcast.spi.impl.operationservice.impl.BackpressureRegulator
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Backpressure is disabled
Apr 09, 2018 5:26:41 PM com.hazelcast.instance.Node
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Activating Discovery SPI Joiner
Apr 09, 2018 5:26:41 PM com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Starting 8 partition threads and 5 generic threads (1 dedicated for priority tasks)
Apr 09, 2018 5:26:41 PM com.hazelcast.internal.diagnostics.Diagnostics
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
Apr 09, 2018 5:26:41 PM com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5701 [dev] [3.9.3] [127.0.0.1]:5701 is STARTING
09-Apr-2018 17:26:46.770 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Users/cheni04/lac/workspace/DeveloperSetup/Servers/Tomcat/apache-tomcat-8.5.24/webapps/manager]
09-Apr-2018 17:26:46.819 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Users/cheni04/lac/workspace/DeveloperSetup/Servers/Tomcat/apache-tomcat-8.5.24/webapps/manager] has finished in [48] ms
Apr 09, 2018 5:26:46 PM com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.9.3] Cluster version set to 3.9
Apr 09, 2018 5:26:46 PM com.hazelcast.internal.cluster.ClusterService
INFO: [127.0.0.1]:5701 [dev] [3.9.3]
Members {size:1, ver:1} [
Member [127.0.0.1]:5701 - b011dd1b-675d-4176-ad7e-839fd813eaed this
]
The number for this node is :1
Apr 09, 2018 5:26:46 PM com.hazelcast.core.LifecycleService
日志输出(来自节点2)
STARTING UP INSTANCE...
Apr 09, 2018 5:27:12 PM com.hazelcast.config.XmlConfigLocator
INFO: Loading 'hazelcast.xml' from classpath.
Apr 09, 2018 5:27:12 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.9.3] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [127.0.0.1]
Apr 09, 2018 5:27:12 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.9.3] Picked [127.0.0.1]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
Apr 09, 2018 5:27:12 PM com.hazelcast.system
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Hazelcast 3.9.3 (20180216 - 539b124) starting at [127.0.0.1]:5702
Apr 09, 2018 5:27:12 PM com.hazelcast.system
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
Apr 09, 2018 5:27:12 PM com.hazelcast.system
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Configured Hazelcast Serialization version: 1
Apr 09, 2018 5:27:13 PM com.hazelcast.spi.impl.operationservice.impl.BackpressureRegulator
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Backpressure is disabled
Apr 09, 2018 5:27:14 PM com.hazelcast.instance.Node
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Activating Discovery SPI Joiner
Apr 09, 2018 5:27:14 PM com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Starting 8 partition threads and 5 generic threads (1 dedicated for priority tasks)
Apr 09, 2018 5:27:14 PM com.hazelcast.internal.diagnostics.Diagnostics
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
Apr 09, 2018 5:27:14 PM com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5702 [dev] [3.9.3] [127.0.0.1]:5702 is STARTING
Apr 09, 2018 5:27:19 PM com.hazelcast.system
INFO: [127.0.0.1]:5702 [dev] [3.9.3] Cluster version set to 3.9
Apr 09, 2018 5:27:19 PM com.hazelcast.internal.cluster.ClusterService
INFO: [127.0.0.1]:5702 [dev] [3.9.3]
Members {size:1, ver:1} [
Member [127.0.0.1]:5702 - 4c7d74d6-0c13-4142-807b-48ab57fd7981 this
]
Apr 09, 2018 5:27:19 PM com.hazelcast.instance.Node
WARNING: [127.0.0.1]:5702 [dev] [3.9.3] Config seed port is 5701 and cluster size is 1. Some of the ports seem occupied!
Apr 09, 2018 5:27:19 PM com.hazelcast.core.LifecycleService
The number for this node is :1
INFO: [127.0.0.1]:5702 [dev] [3.9.3] [127.0.0.1]:5702 is STARTED
答案 0 :(得分:2)
您有<property name="hazelcast.discovery.enabled">true</property>
将此更改为<property name="hazelcast.discovery.enabled">false</property>
或将其删除,一切正常
此属性主要用于激活自定义发现插件(对于Kubernetes,Eureka等),而不是内置插件,如TCP或多播。 你想要TCP。