Hot Rod C++ clients allow C++ runtime applications to connect and interact with remote Infinispan clusters.
1. Installing the Hot Rod C++ client
Install the Hot Rod C++ client on your host system as a dynamic library.
1.1. C++ compiler requirements
Operating system | Required compiler |
---|---|
Red Hat Enterprise Linux (RHEL) 8 |
C++ 11 compiler (GCC 8.5.0) |
RHEL 9 |
C++ 11 compiler (GCC 11.3.1) |
Microsoft Windows 7 x64 |
C++ 11 compiler (Visual Studio 14 2015 Win64, Microsoft Visual C++ 2013 Redistributable Package for the x64 platform) |
1.2. Installing Hot Rod C++ clients on Red Hat Enterprise Linux (RHEL)
Infinispan provides an RPM distribution of the Hot Rod C++ client for RHEL.
-
Download the Hot Rod C++ client from Hot Rod client downloads.
-
Install the RPM with either the
yum
package manager ordnf
utility.# yum localinstall infinispan-hotrod-cpp-<version>-RHEL-x86_64.rpm
1.3. Installing Hot Rod C++ clients on Microsoft Windows
Infinispan provides an archived version of the Hot Rod C++ client for installation on Windows.
-
Download the ZIP archive for the Hot Rod C++ client from the Hot Rod client downloads.
-
Extract the ZIP archive to your file system.
2. Compiling Protobuf Schema
Infinispan uses the ProtoStream API to store data as Protobuf-encoded entries.
Protobuf is a language-neutral format that allows clients to create and retrieve entries in remote caches using both Hot Rod and REST endpoints.
2.1. Compiling Protobuf schema on Red Hat Enterprise Linux (RHEL)
Compile Protobuf schema, .proto
files, into C++ header and source files to describe your data to Infinispan.
-
Install the Protobuf library and
protobuf-devel
package.# yum install protobuf # yum install protobuf-devel
-
Set the
LD_LIBRARY_PATH
environment variable, if it is not already set.# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/lib64
-
Compile Protobuf schema for the Hot Rod C++ client as required.
# /bin/protoc --cpp_out dllexport_decl=HR_PROTO_EXPORT:/path/to/output/ $FILE
HR_PROTO_EXPORT
is a macro that the Hot Rod C++ client expands when it compiles the Protobuf schema. -
Register your Protobuf schema with Infinispan if you plan to use queries.
2.2. Compiling Protobuf schema on Microsoft Windows
Compile Protobuf schema, .proto
files, into C++ header and source files to describe your data to Infinispan.
-
Open a command prompt to the installation directory for the Hot Rod C++ client.
-
Compile Protobuf schema for the Hot Rod C++ client as required.
bin\protoc --cpp_out dllexport_decl=HR_PROTO_EXPORT:path\to\output\ $FILE
HR_PROTO_EXPORT
is a macro that the Hot Rod C++ client expands when it compiles the Protobuf schema. -
Register your Protobuf schema with Infinispan if you plan to use queries.
3. Configuring the Hot Rod C++ client
Hot Rod C++ clients interact with remote Infinispan clusters via the RemoteCache
API.
3.1. Configuration and Remote Cache Manager APIs
Use the ConfigurationBuilder
API to configure Hot Rod C++ client connections and the RemoteCacheManager
API to obtain and configure remote caches.
#include "infinispan/hotrod/ConfigurationBuilder.h"
#include "infinispan/hotrod/RemoteCacheManager.h"
#include <infinispan/hotrod/RemoteCache.h>
#include <iostream>
int main () {
ConfigurationBuilder builder;
// Configure a cache manager to connect with Hot Rod version 2.8
builder.protocolVersion(Configuration::PROTOCOL_VERSION_28);
// Connect to a server at localhost with the default port.
builder.addServer().host("127.0.0.1").port(11222);
// Create and start a RemoteCacheManager to interact with caches.
RemoteCacheManager cacheManager(builder.build(), false);
cacheManager.start();
...
}
ConfigurationBuilder builder;
builder.addServer().host("127.0.0.1").port(11222);
// Configure a remote cluster and node when using cross-site replication.
builder.addCluster("NYC").addClusterNode("192.0.2.0", 11322);
ConfigurationBuilder builder;
builder.addServer().host("127.0.0.1").port(11222);
// Enable near-caching for the client.
builder.nearCache().mode(NearCacheMode::INVALIDATED).maxEntries(4);