gpt4 book ai didi

java - Hazelcast 嵌入式模式 - 如何连接到集群并从属于集群的节点检索 map ?

转载 作者:行者123 更新时间:2023-12-02 02:14:28 25 4
gpt4 key购买 nike

我有一个包含两个节点的 hazelcast 嵌入式集群。如果我使用 HazelcastClient.newHazelcastClient() 实例,我可以访问集群中的 map ,但如果我使用 Hazelcast.newHazelcastInstance(),我无法获得相同的结果。如果我从一个节点操纵 map ,则另一个节点在完全不同的 map 上工作;变化并不存在。

是否要求我应该使用 HazelcastClient 实例连接到嵌入式 hazelcast 集群。当您拥有实际的集群实例对象时,似乎没有必要在嵌入模式下创建和配置客户端 (hazelcast-client.xml)。

编辑:- 使用的发现机制是 TCP。

下面显示的设置有两个简单的 java WAR 文件,它们运行在同一台机器上运行的两个不同的 tomcat 上。我通过 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

最佳答案

您有<property name="hazelcast.discovery.enabled">true</property>

将其更改为 <property name="hazelcast.discovery.enabled">false</property>或者删除它,一切都应该没问题

此属性主要用于激活自定义发现插件(适用于 Kubernetes、Eureka 等),而不是 TCP 或多播等内置插件。您需要 TCP。

关于java - Hazelcast 嵌入式模式 - 如何连接到集群并从属于集群的节点检索 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49500918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com