Chapter 14. Clients

Table of Contents

14.1. Native Client
14.1.1. Java Client
14.1.2. CSharp Client
14.2. Memcache Client
14.3. Rest Client

There are currently three ways to connect to a running Hazelcast cluster:

  1. Native Clients

  2. Memcache Clients

  3. REST Client

14.1. Native Client

Native Client enables you to do all Hazelcast operations without being a member of the cluster. It connects to one of the cluster members and delegates all cluster wide operations to it. When the relied cluster member dies, client will transparently switch to another live member.

There can be hundreds, even thousands of clients connected to the cluster.

Imagine a trading application where all the trading data stored and managed in a 10 node Hazelcast cluster. Swing/Web applications at traders' desktops can use Native Java Client to access and modify the data in the Hazelcast cluster.

Currently Hazelcast has Native Java Client available. The next client implementation will be CSharp.

Super Client vs. Native Client

Super Client is a member of the cluster, it has socket connection to every member in the cluster and it knows where the data is so it will get to the data much faster. But Super Client has the clustering overhead and it must be on the same data center even on the same RAC. However Native client is not member and relies on one of the cluster members. Native Clients can be anywhere in the LAN or WAN. It scales much better and overhead is quite less. So if your clients are less than Hazelcast nodes then Super client can be an option; otherwise definitely try Native Client. As a rule of thumb: Try Native client first, if it doesn't perform well enough for you, then consider Super client.

The following picture describes the clients connecting to Hazelcast Cluster. Note the difference between Super Client and Java Client

14.1.1. Java Client

You can do almost all hazelcast operations with Java Client. It already implements the same interface. You must include hazelcast-client.jar into your classpath.

    import com.hazelcast.core.HazelcastInstance;
    import com.hazelcast.client.HazelcastClient;

    import java.util.Map;
    import java.util.Collection;


    HazelcastInstance client = HazelcastClient.newHazelcastClient("dev", "dev-pass", "10.90.0.1", "10.90.0.2:5702");
    //All Cluster Operations that you can do with ordinary HazelcastInstance
    Map<String, Customer> mapCustomers = client.getMap("customers");
    mapCustomers.put("1", new Customer("Joe", "Smith"));
    mapCustomers.put("2", new Customer("Ali", "Selam"));
    mapCustomers.put("3", new Customer("Avi", "Noyan"));

    Collection<Customer> colCustomers = mapCustomers.values();
    for (Customer customer : colCustomers) {
         // process customer
    }

14.1.2. CSharp Client

CSharp client is not available yet.