Connecting to a Remote Infinispan Server using Hot Rod

In this tutorial you will learn how to configure and use Infinispan 8.1 and use some of its API.

The server version of Infinispan is available at:

Behind the hoods the new server version is bundled into a WildFly installation, therefore you will have to configure Infinispan through the infinispan subsystem. The standalone server contains two configurations:

  • standalone.xml (non-clustered cache)
  • clustered.xml (clustered Infinispan distribution)

Here follows the clustered configuration:

<subsystem xmlns="urn:infinispan:server:core:8.1" default-cache-container="clustered">
    <cache-container name="clustered" default-cache="default" statistics="true">
        <transport lock-timeout="60000"/>
        <distributed-cache name="default" mode="SYNC" segments="20" owners="2" remote-timeout="30000" start="EAGER">
            <locking acquire-timeout="30000" concurrency-level="1000" striping="false"/>
            <transaction mode="NONE"/>
        <distributed-cache name="memcachedCache" mode="SYNC" segments="20" owners="2" remote-timeout="30000" start="EAGER">
            <locking acquire-timeout="30000" concurrency-level="1000" striping="false"/>
            <transaction mode="NONE"/>
        <distributed-cache name="namedCache" mode="SYNC" start="EAGER"/>
        <distributed-cache name="transactionalCache" mode="SYNC" start="EAGER">
            <transaction mode="NON_XA" locking="PESSIMISTIC"/>

Basically, Infinispan offers two access patterns, both of which are available in any runtime:

  • Embedded into your application code
  • As a Remote server accessed by a client (REST, memcached or Hot Rod wire protocols are supported)

In the latter case, you will need some connectors which enable receiving calls from remote clients:

<subsystem xmlns="urn:infinispan:server:endpoint:8.0">
    <hotrod-connector socket-binding="hotrod" cache-container="clustered">
        <topology-state-transfer lazy-retrieval="false" lock-timeout="1000" replication-timeout="5000"/>
    <memcached-connector socket-binding="memcached" cache-container="clustered"/>
    <rest-connector socket-binding="rest" cache-container="clustered" security-domain="other" auth-method="BASIC"/>
    <websocket-connector socket-binding="websocket" cache-container="clustered"/>

Let’s see as an example an HotRod client application which connects to the “default” clustered caches, and adds some data to it. At first we will start a cluster of Infinispan nodes. This can be easily achieved starting the server in domain mode, which is bound to the “clustered” profile.


Check from the logs that the server started and that the clusted was correclty composed:

[Server:server-one] 19:47:03,254 INFO [org.infinispan.CLUSTER] (remote-thread--p2-t4) ISPN000310: Starting cluster-wide rebalance for cache ___hotRodTopologyCache, topology CacheTopology{id=1, rebalanceId=1, currentCH=ReplicatedConsistentHash{ns = 60, owners = (1)[master:server-one: 60]}, pendingCH=ReplicatedConsistentHash{ns = 60, owners = (2)[master:server-one: 30, master:server-two: 30]}, unionCH=null, actualMembers=[master:server-one, master:server-two]}

Now let’s connect to the Infinispan cluster with some code:

package com.mastertheboss;

import java.util.Iterator;
import java.util.Map;

import java.util.Set;
import java.util.UUID;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.ServerStatistics;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;

public class DemoHotRod {

    private RemoteCacheManager cacheManager;
    private RemoteCache<String, Object> cache;

    public DemoHotRod() {

        ConfigurationBuilder builder = new ConfigurationBuilder();
        cacheManager = new RemoteCacheManager(;

        cache = cacheManager.getCache("default");

        cache.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());

        System.out.println("Dumping cache Data");
        Set set = this.cache.keySet();
        Iterator i = set.iterator();
        while (i.hasNext()) {
        //Print cache statistics
        ServerStatistics stats = cache.stats();
        for (Map.Entry stat : stats.getStatsMap().entrySet()) {
            System.out.println(stat.getKey() + " : " + stat.getValue());


    public static void main(String[] args) {

        DemoHotRod manager = new DemoHotRod();



In order to compile the class, you will need to incude the Infinispan core libraries and the Hot Rod client APIs, plus their dependencies. The simplest way to do that is by means of the following Maven’s pom.xml:

<project xmlns="" xmlns:xsi=""

    <name>Hot Rod Client Demo</name>


        <!-- other plugin versions -->


        <!-- Import the infinispan core -->

        <!-- Import the Infinispan client hotrod -->

        <!-- Maven will append the version to the finalName (which is the 
            name given to the generated jar) -->
            <!-- This plugin permits the execution of this quickstart 
                through mvn exec:java command -->

You can compile the class with:

$ mvn clean install

And run the application with:

$ mvn exec:java

As a result, you should see in your cache an entry named

Dumping cache Data

currentNumberOfEntries : 1
hits : 0
removeHits : 0
totalBytesRead : 15
timeSinceStart : 214
removeMisses : 0
totalNumberOfEntries : 0
stores : 0
misses : 0
retrievals : 0
totalBytesWritten : 0