此内容没有您所选择的语言版本。

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

  1. Open a remote shell to a Data Grid node, for example:

    $ oc rsh example-rhdatagrid
    Copy to Clipboard Toggle word wrap
  2. 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
      ...
    Copy to Clipboard Toggle word wrap
  3. 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
    Copy to Clipboard Toggle word wrap
  4. Verify the entry.

    $ curl -X GET \
      -u developer:$PASSWORD \
      $SERVICE_HOSTNAME:11222/rest/v2/caches/default/hello/
      ...
      < HTTP/1.1 200 OK
      ...
      world
    Copy to Clipboard Toggle word wrap

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);
Copy to Clipboard Toggle word wrap

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
Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat