6.3. 连接在 OpenShift 上运行的 Hot Rod 客户端
使用在与 Data Grid 集群相同的 OpenShift 集群上运行的 Hot Rod 客户端访问远程缓存。
先决条件
- 检索网络服务详细信息。
流程
在客户端配置中为您的 Data Grid 集群指定内部网络服务详情。
在以下配置示例中,
$SERVICE_HOSTNAME:$PORT表示允许访问您的 Data Grid 集群的主机名和端口。- 指定您的凭证,以便客户端可以通过 Data Grid 进行身份验证。
如果需要,配置客户端智能。
在 OpenShift 上运行的热 Rod 客户端可以使用任何客户端智能功能,因为它们可以访问 Data Grid Pod 的内部 IP 地址。
建议使用默认智能HASH_DISTRIBUTION_AWARE,因为它允许客户端将请求路由到主要所有者,从而提高性能。
Programmatic 配置
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
6.3.1. 获取所有 Data Grid pod 的 IP 地址 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
您可以检索用于运行 Data Grid pod 的所有 IP 地址列表。
重要
在 OpenShift 上运行的 Hot Rod 客户端是推荐的方法,因为它可确保初始连接到 其中一个可用 pod。
流程
使用以下命令为正在运行的 Data Grid pod 获取所有 IP 地址:
使用 OpenShift API:
-
访问
${APISERVER}/api/v1/namespaces/<chart-namespace>/endpoints/<helm-release-name>,以检索与 <helm-release-name> 服务关联的端点OpenShift 资源。
-
访问
使用 OpenShift DNS 服务:
-
查询 DNS 服务名称 <
;helm-release-name>-ping以获取集群中所有节点的 IP。
-
查询 DNS 服务名称 <