JK_007
JK_007

Reputation: 125

Unique name for Hazelcast client instances

I have 3 node hazelcast server cluster and hazelcast client is started in each node. The hazelcast client uses smart routing and client / server mode is used.

I collect the list of clients connected to Hazelcast server cluster via IExecutorService and ClientService.getConnectedClients() in each Hazelcast client. After fetching the list I want to loop through the fetched list of client and compare it with own instance (the client who fetched the list) and if found perform some application logic. One way to do is to assign a unique name to client during HazelcastClient.newHazelcastClient.

Is it possible to have a unique name set to each Hazelcast client instance ? .

Please let me know if I am not clear.

Thanks JK

Upvotes: 2

Views: 4716

Answers (2)

em-chips
em-chips

Reputation: 1

If you can wait til Hazelcast 3.6,

https://github.com/hazelcast/hazelcast/blob/master/hazelcast-client/src/main/java/com/hazelcast/client/config/ClientConfig.java has public void setInstanceName(String instanceName)

Upvotes: 0

Dinesh
Dinesh

Reputation: 983

You can identify a hazelcast client uniquely as follows.

HazelcastInstance clientInstance = HazelcastClient.newHazelcastClient(clientConfig);
String localUUID = clientInstance.getLocalEndpoint().getUuid();
System.out.println("Client UUID is  : " + localUUIID);

In the next step, retrieve the connected clients list using ExecutorService --> ClientService.getConnectedClients and then iterate over the list as follows.

for(com.hazelcast.core.Client client : clients)
{
    if(localUUID.equals(client.getUuid()))
    {
        System.out.println("Found : " + client.getUuid());
        // perform your logic here...
        break;
    }
}

There you go !

Upvotes: 4

Related Questions