12.4. 从 Hot Rod 客户端创建远程缓存

使用 Data Grid Hot Rod API 从 Java、C++、.NET/C#、JS 客户端等在 Data Grid Server 上创建远程缓存。

此流程演示了如何使用 Hot Rod Java 客户端在第一次引导时创建远程缓存。您可以在 Data Grid Tutorials 中找到其他 Hot Rod 客户端的代码示例。

先决条件

  • 创建具有管理权限的 Data Grid 用户
  • 至少启动一个数据网格服务器实例。
  • 具有数据网格缓存配置。

流程

  • 调用 remoteCache () 方法,作为 ConfigurationBuilder 的一部分。
  • 在类路径上的 hotrod-client.properties 文件中设置 configurationconfiguration_uri 属性。

ConfigurationBuilder

File file = new File("path/to/infinispan.xml")
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.remoteCache("another-cache")
       .configuration("<distributed-cache name=\"another-cache\"/>");
builder.remoteCache("my.other.cache")
       .configurationURI(file.toURI());

hotrod-client.properties

infinispan.client.hotrod.cache.another-cache.configuration=<distributed-cache name=\"another-cache\"/>
infinispan.client.hotrod.cache.[my.other.cache].configuration_uri=file:///path/to/infinispan.xml

重要

如果远程缓存的名称包含 . 字符,在使用 hotrod-client.properties 文件时,必须将其括在方括号中。