Hi,
I am running multiple hazelcast members with below configuration on two machines with the configuration below.
<tcp-ip enabled="true">
<member>192.168.0.111</member>
<member>192.168.0.101</member>
</tcp-ip>
I am starting the nodes with below code snippet
String configFileLocation="hazelcast/member/hazelcast.xml";
cfg=new ClasspathXmlConfig(configFileLocation);
instance = Hazelcast.newHazelcastInstance(cfg);
I have three java clients using the configuration
<cluster-members>
<address>192.168.0.111</address>
<address>192.168.0.101</address>
</cluster-members>
I am starting the clients using code below
String configFileLocation="hazelcast/client/hazelcast-client.xml";
InputStream is = getClass().getClassLoader().getResourceAsStream(configFileLocation);
cfg = new XmlClientConfigBuilder(is).build();
instance = HazelcastClient.newHazelcastClient(cfg);
I am creating adding listeners for IMap as below
instance.getMap("MyMap").addEntryListener(new MyMapEntryListener(), true)
class MyMapEntryListener extends EntryAddedListener<String, String>{
public void entryAdded(EntryEvent<String, String> event) {
//Some operation
}
}
Entry may be added by any client/members to the Map and all clients need to process it. Initially, everything works fine.
The issue occurs when I kill one node (Manually ctrl+c or kill -9 ). Sometimes my clients are not able to listen to the map even though there is at least one member is alive. The issue is random with clients, some clients work fine or some not.
I see the below exception in client logs
13:11:22.587 6556933 [http-apr-9090-exec-2] ERROR c.s.f.t.channel.StreamingTrading - Exception Listener can not be added com.hazelcast.core.HazelcastException: Listener can not be added
or
Caused by: java.util.concurrent.ExecutionException: java.io.IOException: Target : Address[192.168.0.111]:5701 is not member.
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveResponse(ClientInvocationFuture.java:141) ~[hazelcast-all-3.6.2.jar:3.6.2]
I tried to add or remove listener on hazelcast instance life cycle but did not help.
instance.getLifecycleService().addLifecycleListener(new HzLifecycleListener());
class HzLifecycleListener implements LifecycleListener {
@Override
public void stateChanged(LifecycleEvent event) {
switch (event.getState()) {
case SHUTDOWN:
//Hazelcast cluster is shutdown. Try to connect again
break;
case STARTED:
break;
case CLIENT_CONNECTED:
//Set the listener again
break;
case CLIENT_DISCONNECTED:
//remove the listener
break;
default:
break;
}
}
}
Can someone please guide me, how to manage the listeners on hazelcast client, so if any of the node in clusters goes down it will not impact it. What is the best possible approach to solving this issue?