17.5. 热 Rod 客户端


hot Rod 是一个二进制 TCP 协议,Data Grid 提供带有远程客户端的高性能数据传输功能。

客户端智能

客户端智能指的是 Hot Rod 协议提供的机制,以便客户端可以定位并发送请求到 Data Grid pod。

在 OpenShift 上运行的热 Rod 客户端可以访问 Data Grid pod 的内部 IP 地址,以便您可以使用任何客户端智能。建议默认智能 HASH_DISTRIBUTION_AWARE,因为它允许客户端将请求路由到主所有者,从而提高性能。

在 OpenShift 外部运行的热 Rod 客户端必须使用 BASIC 智能。

17.5.1. hot Rod 客户端配置 API

您可以使用 ConfigurationBuilder 接口以编程方式配置 Hot Rod 客户端连接。

注意

$SERVICE_HOSTNAME:$PORT 表示允许访问您的数据网格集群的主机名和端口。您应该使用环境的实际主机名和端口替换这些变量。

在 OpenShift 中

在 OpenShift 上运行的热 Rod 客户端可使用以下配置:

import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.SaslQop;
import org.infinispan.client.hotrod.impl.ConfigurationProperties;
...

ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.addServer()
               .host("$SERVICE_HOSTNAME")
               .port(ConfigurationProperties.DEFAULT_HOTROD_PORT)
             .security().authentication()
               .username("username")
               .password("changeme")
               .realm("default")
               .saslQop(SaslQop.AUTH)
               .saslMechanism("SCRAM-SHA-512")
             .ssl()
               .sniHostName("$SERVICE_HOSTNAME")
               .trustStoreFileName("/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt")
               .trustStoreType("pem");
Copy to Clipboard Toggle word wrap
外部 OpenShift

在 OpenShift 外部运行的热 Rod 客户端可使用以下配置:

import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.SaslQop;
...

ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.addServer()
               .host("$SERVICE_HOSTNAME")
               .port("$PORT")
             .security().authentication()
               .username("username")
               .password("changeme")
               .realm("default")
               .saslQop(SaslQop.AUTH)
               .saslMechanism("SCRAM-SHA-512")
             .ssl()
               .sniHostName("$SERVICE_HOSTNAME")
               //Create a client trust store with tls.crt from your project.
               .trustStoreFileName("/path/to/truststore.pkcs12")
               .trustStorePassword("trust_store_password")
               .trustStoreType("PCKS12");
      builder.clientIntelligence(ClientIntelligence.BASIC);
Copy to Clipboard Toggle word wrap

17.5.2. 热 Rod 客户端属性

您可以使用应用程序 classpath 上的 hotrod-client.properties 文件配置 Hot Rod 客户端连接。

注意

$SERVICE_HOSTNAME:$PORT 表示允许访问您的数据网格集群的主机名和端口。您应该使用环境的实际主机名和端口替换这些变量。

在 OpenShift 中

在 OpenShift 上运行的热 Rod 客户端可使用以下属性:

# Connection
infinispan.client.hotrod.server_list=$SERVICE_HOSTNAME:$PORT

# Authentication
infinispan.client.hotrod.use_auth=true
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=SCRAM-SHA-512

# Encryption
infinispan.client.hotrod.sni_host_name=$SERVICE_HOSTNAME
infinispan.client.hotrod.trust_store_file_name=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
infinispan.client.hotrod.trust_store_type=pem
Copy to Clipboard Toggle word wrap
外部 OpenShift

在 OpenShift 外部运行的热 Rod 客户端可使用以下属性:

# Connection
infinispan.client.hotrod.server_list=$SERVICE_HOSTNAME:$PORT

# Client intelligence
infinispan.client.hotrod.client_intelligence=BASIC

# Authentication
infinispan.client.hotrod.use_auth=true
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=SCRAM-SHA-512

# Encryption
infinispan.client.hotrod.sni_host_name=$SERVICE_HOSTNAME
# Create a client trust store with tls.crt from your project.
infinispan.client.hotrod.trust_store_file_name=/path/to/truststore.pkcs12
infinispan.client.hotrod.trust_store_password=trust_store_password
infinispan.client.hotrod.trust_store_type=PCKS12
Copy to Clipboard Toggle word wrap

17.5.3. 为证书身份验证配置 Hot Rod 客户端

如果启用了客户端证书身份验证,客户端必须在与 Data Grid 进行连接时显示有效的证书。

验证策略

如果使用 Validate 策略,则必须使用密钥存储配置客户端,以便它们能够提供签名证书。您还必须使用 Data Grid 凭证和任何合适的身份验证机制配置客户端。

验证策略

如果使用 Authenticate 策略,则必须使用包含签名证书和有效 Data Grid 凭证的密钥存储配置客户端,作为可分辨名称(DN)的一部分。热 Rod 客户端还必须使用 EXTERNAL 身份验证机制。

注意

如果启用安全授权,您应该为来自客户端证书的通用名称(CN)分配一个具有适当权限的角色。

以下示例显示了使用 Authenticate 策略进行客户端证书身份验证的 Hot Rod 客户端配置:

import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
...

ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.security()
             .authentication()
               .saslMechanism("EXTERNAL")
             .ssl()
               .keyStoreFileName("/path/to/keystore")
               .keyStorePassword("keystorepassword".toCharArray())
               .keyStoreType("PCKS12");
Copy to Clipboard Toggle word wrap

17.5.4. 从 Hot Rod 客户端创建缓存

您可以使用 Hot Rod 客户端在 OpenShift 上运行的 Data Grid 集群上远程创建缓存。但是,Data Grid 建议使用 Data Grid 控制台、CLI 或带有 Cache CR 而不是 Hot Rod 客户端创建缓存。

以编程方式创建缓存

以下示例演示了如何将缓存配置添加到 ConfigurationBuilder 中,然后使用 RemoteCacheManager 创建它们:

import org.infinispan.client.hotrod.DefaultTemplate;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
...

      builder.remoteCache("my-cache")
             .templateName(DefaultTemplate.DIST_SYNC);
      builder.remoteCache("another-cache")
             .configuration("<infinispan><cache-container><distributed-cache name=\"another-cache\"><encoding media-type=\"application/x-protostream\"/></distributed-cache></cache-container></infinispan>");
      try (RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build())) {
      // Get a remote cache that does not exist.
      // Rather than return null, create the cache from a template.
      RemoteCache<String, String> cache = cacheManager.getCache("my-cache");
      // Store a value.
      cache.put("hello", "world");
      // Retrieve the value and print it.
      System.out.printf("key = %s\n", cache.get("hello"));
Copy to Clipboard Toggle word wrap

本例演示了如何使用 XMLStringConfiguration () 方法创建名为 CacheWithXMLConfiguration 的缓存,将缓存配置作为 XML 传递:

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.commons.configuration.XMLStringConfiguration;
...

private void createCacheWithXMLConfiguration() {
    String cacheName = "CacheWithXMLConfiguration";
    String xml = String.format("<distributed-cache name=\"%s\">" +
                                  "<encoding media-type=\"application/x-protostream\"/>" +
                                  "<locking isolation=\"READ_COMMITTED\"/>" +
                                  "<transaction mode=\"NON_XA\"/>" +
                                  "<expiration lifespan=\"60000\" interval=\"20000\"/>" +
                                "</distributed-cache>"
                                , cacheName);
    manager.administration().getOrCreateCache(cacheName, new XMLStringConfiguration(xml));
    System.out.println("Cache with configuration exists or is created.");
}
Copy to Clipboard Toggle word wrap
使用 Hot Rod 客户端属性

当您为指定缓存调用 cacheManager.getCache () 调用时,Data Grid 从 Hot Rod 客户端属性创建它们,而不是返回 null。

hotrod-client.properties 中添加缓存配置,如下例所示:

# Add cache configuration
infinispan.client.hotrod.cache.my-cache.template_name=org.infinispan.DIST_SYNC
infinispan.client.hotrod.cache.another-cache.configuration=<infinispan><cache-container><distributed-cache name=\"another-cache\"/></cache-container></infinispan>
infinispan.client.hotrod.cache.my-other-cache.configuration_uri=file:/path/to/configuration.xml
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat