1.3. 请求负载平衡


热 Rod Java 客户端平衡对数据平面集群的请求,以便读取和写入操作分散到节点上。

使用 BASICTOPOLOGY_AWARE 智能的客户端为所有请求使用请求平衡。使用 HASH_DISTRIBUTION_AWARE 智能的客户端将请求直接发送到存储所需密钥的节点。如果节点没有响应,客户端会返回请求均衡。

默认平衡策略是循环的,因此 Hot Rod 客户端执行请求平衡,如下例所示,s1s 2、s3 是 Data Grid 集群中的节点:

// Connect to the Data Grid cluster
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// Obtain the remote cache
RemoteCache<String, String> cache = cacheManager.getCache("test");

//Hot Rod client sends a request to the "s1" node
cache.put("key1", "aValue");
//Hot Rod client sends a request to the "s2" node
cache.put("key2", "aValue");
//Hot Rod client sends a request to the "s3" node
String value = cache.get("key1");
//Hot Rod client sends the next request to the "s1" node again
cache.remove("key2");
Copy to Clipboard Toggle word wrap

自定义平衡策略

如果在 Hot Rod 客户端配置中添加类,您可以使用自定义 FailoverRequestBalancingStrategy 实现。

ConfigurationBuilder

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
         .host("127.0.0.1")
         .port(11222)
         .balancingStrategy(new MyCustomBalancingStrategy());
Copy to Clipboard Toggle word wrap

hotrod-client.properties

infinispan.client.hotrod.request_balancing_strategy=my.package.MyCustomBalancingStrategy
Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat