Search code examples
javahazelcast

Hazelcast Embedded mode - How to connect to the cluster and retrieve a map from a node that is part of the cluster?


I have a hazelcast embedded cluster of two nodes. I can access a map in the cluster if i go about using a HazelcastClient.newHazelcastClient() instance but i am not able to get the same results if i use the Hazelcast.newHazelcastInstance(). If i manipulate the map from one node, the other node works on a totally different map ; the changes arent there.

Is it a requirement that i should use a HazelcastClient instance to connect to an embedded hazelcast cluster. It seems unnecessary to create and configure clients (hazelcast-client.xml) in embedded mode when you have the actual cluster instance object available.

EDIT:- The discovery mechanism used is TCP.

Setup shown below has two simple java WAR files running on two different tomcats running on the same machine. I make them discoverable via the TCP discovery mechanism as shown below.

hazelcast.xml ( top part only )

<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>

Log Output ( from node 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

Log Output ( from node 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

Solution

  • You have <property name="hazelcast.discovery.enabled">true</property>

    Change this to <property name="hazelcast.discovery.enabled">false</property> or remove it, and all should be ok

    This property is mainly intended for activation of custom discovery plugins (for Kubernetes, Eureka, etc) instead of the built-ins such as TCP or Multicast. You want TCP here.