5.3. 连接在 OpenShift 上运行的 Hot Rod 客户端
使用与 Data Grid 集群在同一 OpenShift 集群上运行的 Hot Rod 客户端访问远程缓存。
先决条件
- 检索网络服务详细信息。
流程
在客户端配置中,为您的 Data Grid 集群指定内部网络服务详情。
在以下配置示例中,
$SERVICE_HOSTNAME:$PORT表示可访问您的 Data Grid 集群的主机名和端口。- 指定凭证以便客户端可以通过 Data Grid 进行身份验证。
如果需要,配置客户端智能。
在 OpenShift 上运行的热环客户端可以使用任何客户端智能,因为它们可以访问 Data Grid Pod 的内部 IP 地址。
建议默认智能HASH_DISTRIBUTION_AWARE,因为它允许客户端将请求路由到主要所有者,从而提高性能。
程序配置
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");
热 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