Connecting applications
Hot Rod and REST clients for Data Grid from Spring Boot, Quarkus and .NET, including the Kubernetes setting that makes topology-aware clients fail.
Port 11222 serves two protocols. Hot Rod is the binary one Java clients should use: it pipelines, it balances, and it can stay up as pods roll. REST is the one everything else can speak with an HTTP library, including .NET. Both authenticate with the same user. The cluster is example-infinispan in datagrid, the cache is catalog, and the password is in example-infinispan-generated-secret from the install lab.
The one setting that matters on OpenShift
Hot Rod's default client intelligence asks the server which pod owns a key, then connects to that pod's address. Those addresses are pod IPs. From a laptop, and often from a namespace with no route to the pod network, the connection hangs after the first successful handshake to the Service. Set the client to BASIC. It then uses only the Service DNS you configured, and the Service load-balances.
TLS is on. The certificate is signed by the cluster's service CA. A Java truststore that does not contain /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt will fail the handshake. Mount that file. For a first test inside the cluster, the examples below trust it.
Quarkus
The dependency is quarkus-infinispan-client.
quarkus.infinispan-client.hosts=example-infinispan.datagrid.svc:11222
quarkus.infinispan-client.username=developer
quarkus.infinispan-client.password=${DG_PASSWORD}
quarkus.infinispan-client.sasl-mechanism=SCRAM-SHA-512
quarkus.infinispan-client.client-intelligence=BASIC
@ApplicationScoped
public class Catalog {
@Inject RemoteCacheManager manager;
public String price(String sku) {
return manager.<String, String>getCache("catalog").get(sku);
}
}
DG_PASSWORD comes from a Secret key, injected as an environment variable. Do not put the password in application.properties and commit it. If SCRAM-SHA-512 is rejected, read the server log for the mechanisms it offered and use that name. The operator's default on the 8.5 line is SCRAM. Older servers advertise DIGEST-MD5.
getCache("catalog") does not create the cache. The Cache CR does. An application that creates caches at startup needs the deployer role, which developer may not have once you tighten authorization in the security lab.
Spring Boot
Use the remote starter, not the embedded one. Embedded starts a private Infinispan inside the application pod, which is a different system and will not see the cluster.
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring-boot3-starter-remote</artifactId>
</dependency>
infinispan.remote.server-list=example-infinispan.datagrid.svc:11222
infinispan.remote.auth-username=developer
infinispan.remote.auth-password=${DG_PASSWORD}
infinispan.remote.sasl-mechanism=SCRAM-SHA-512
infinispan.remote.client-intelligence=BASIC
infinispan.remote.marshaller=org.infinispan.commons.marshall.ProtoStreamMarshaller
ProtoStream is the marshaller you want if this client will later run the queries from the querying lab. For a String cache, the default Java marshaller appears to work and then breaks the moment a .NET or REST client reads the same key. Pick one encoding per cache. application/json in the cache template matches REST and a String value. Protobuf matches Hot Rod queries. Do not mix them in catalog.
@Bean
RemoteCache<String, String> catalog(RemoteCacheManager manager) {
return manager.getCache("catalog");
}
A GET of sku-42 after the curl in the install lab returns 120. If it returns null and REST returns 120, the marshaller does not match the encoding. That is the first place to look.
.NET
There is no supported Hot Rod client in the .NET base class library. Call REST. The cache is already application/json or plain text.
var client = new HttpClient();
var token = Convert.ToBase64String(Encoding.ASCII.GetBytes($"developer:{password}"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", token);
var json = await client.GetStringAsync(
"https://example-infinispan.datagrid.svc:11222/rest/v2/caches/catalog/sku-42");
Trust the service CA. HttpClient against https:// with no custom handler will reject the cluster-signed certificate. Mount service-ca.crt into the pod and add it to the handler, or terminate with a certificate your platform already trusts. Timeouts belong on the client. A Data Grid blip should not pin a request thread forever.
Basic authentication over TLS is appropriate here. Basic authentication over plain HTTP would put the password on the wire. Do not turn TLS off to make the C# easier.
From outside the cluster
oc port-forward svc/example-infinispan 11222:11222 -n datagrid and then https://localhost:11222 works for a person. It is not how the application connects. The application uses the Service DNS. A port-forward that works and a pod that does not is almost always BASIC intelligence, DNS, or the truststore.
Check from a pod in the application namespace:
oc exec -n app deploy/catalog-api -- \
getent hosts example-infinispan.datagrid.svc
A name that does not resolve is a namespace or a NetworkPolicy problem, not a Data Grid problem. The security lab adds the policy that would cause exactly that symptom, so apply it after this curl works.
What's next
Session externalisation uses the same Hot Rod connection for HTTP sessions. Querying needs Protobuf on this client. The Redis equivalent of this page is the caching lab, if you are still deciding.