Chapter 10. Connecting to Data Grid Clusters
Connect to Data Grid via the REST or Hot Rod endpoints. You can then remotely create and modify cache definitions and store data across Data Grid clusters.
The examples in this section use $SERVICE_HOSTNAME
to denote the service that provides access to your Data Grid cluster.
Clients running in OpenShift can specify the name of the internal service that Data Grid Operator creates.
Clients running outside OpenShift should specify hostnames according to the type of external service and provider. For example, if using a load balancer service on AWS, the service hostname could be:
.status.loadBalancer.ingress[0].hostname
On GCP or Azure, hostnames might be as follows:
.status.loadBalancer.ingress[0].ip
10.1. Invoking the Data Grid REST API
You can invoke the Data Grid REST API with any appropriate HTTP client.
For convenience, the following examples show how to invoke the REST API with curl
using unencrypted connections. It is beyond the scope of this document to describe how to configure HTTP clients to use encryption.
Procedure
Open a remote shell to a Data Grid node, for example:
$ oc rsh example-rhdatagrid
Cache service provides a default cache instance, but Data Grid service does not. Before you can store data with Data Grid service clusters, you must create a cache as in the following example:
$ curl -X POST \ -u developer:$PASSWORD \ $SERVICE_HOSTNAME:11222/rest/v2/caches/default ... < HTTP/1.1 200 OK ...
Put an entry in the cache.
$ curl -X POST \ -u developer:$PASSWORD \ -H 'Content-type: text/plain' -d 'world' \ $SERVICE_HOSTNAME:11222/rest/v2/caches/default/hello ... < HTTP/1.1 204 No Content
Verify the entry.
$ curl -X GET \ -u developer:$PASSWORD \ $SERVICE_HOSTNAME:11222/rest/v2/caches/default/hello/ ... < HTTP/1.1 200 OK ... world
10.2. Configuring Hot Rod Clients
Configure Hot Rod Java clients to connect to Data Grid clusters.
Hot Rod client ConfigurationBuilder
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer() //Connection .host("$SERVICE_HOSTNAME").port(11222) //Client intelligence //External clients can use `BASIC` intelligence only. .clientIntelligence(ClientIntelligence.BASIC) .security() //Authentication .authentication().enable() //Application user credentials. //The default username is developer. .username("developer") .password("$PASSWORD") .serverName("$CLUSTER_NAME") .saslQop(SaslQop.AUTH) .saslMechanism("DIGEST-MD5") //Encryption .ssl() .sniHostName("$SERVICE_HOSTNAME") //Path to the TLS certificate. //Clients automatically generate trust stores from certificates. .trustStorePath(tls.crt);
Hot Rod client properties
# Connection infinispan.client.hotrod.server_list=$SERVICE_HOSTNAME:11222 # Client intelligence # External clients can use `BASIC` intelligence only. infinispan.client.hotrod.client_intelligence=BASIC # Authentication infinispan.client.hotrod.use_auth=true # Application user credentials. # The default username is developer. infinispan.client.hotrod.auth_username=developer infinispan.client.hotrod.auth_password=$PASSWORD infinispan.client.hotrod.auth_server_name=$CLUSTER_NAME infinispan.client.hotrod.sasl_properties.javax.security.sasl.qop=auth infinispan.client.hotrod.sasl_mechanism=DIGEST-MD5 # Encryption infinispan.client.hotrod.sni_host_name=$SERVICE_HOSTNAME # Path to the TLS certificate. # Clients automatically generate trust stores from certificates. infinispan.client.hotrod.trust_store_path=tls.crt