6.3. 连接在 OpenShift 上运行的 Hot Rod 客户端


使用在与 Data Grid 集群相同的 OpenShift 集群上运行的 Hot Rod 客户端访问远程缓存。

先决条件

  • 检索网络服务详细信息。

流程

  1. 在客户端配置中为您的 Data Grid 集群指定内部网络服务详情。

    在以下配置示例,$SERVICE_HOSTNAME:$PORT 表示允许访问您的 Data Grid 集群的主机名和端口。

  2. 指定您的凭证,以便客户端可以通过 Data Grid 进行身份验证。
  3. 如果需要,配置客户端智能。

    在 OpenShift 上运行的热 Rod 客户端可以使用任何客户端智能,因为它们可以访问 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");
Copy to Clipboard Toggle word wrap

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

6.3.1. 获取所有 Data Grid pod 的 IP 地址

您可以检索用于运行 Data Grid pod 的所有 IP 地址列表。

重要

建议使用 Hot Rod 客户端连接 OpenShift 上运行的 Hot Rod 客户端,因为它确保了与其中一个可用容器集的初始连接。

流程

使用以下方法获取正在运行的 Data Grid pod 的所有 IP 地址:

  • 使用 OpenShift API:

    • 访问 ${APISERVER}/api/v1/namespaces/<chart-namespace>/endpoints/<helm-release-name& gt; 来检索与 < helm-release-name > 服务关联的 端点 OpenShift 资源。
  • 使用 OpenShift DNS 服务:

    • 查询 DNS 服务以获取名称 & lt;helm-release-name>-ping,以获取集群中所有节点的 IP。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat