如何使用 java 代码连接到 GemFire 集群,获取区域并将一些值从客户端放入这些区域。
问问题
411 次
1 回答
0
在官方用户指南中,特别是在客户端/服务器示例配置中,有几个示例说明了您要实现的目标。下面是一个极简主义的例子。
服务器缓存.xml
<cache>
<cache-server/>
<region name="TEST">
<region-attributes refid="REPLICATE"/>
</region>
</cache>
客户端缓存.xml
<client-cache>
<pool name="default">
<locator host="localhost" port="10334"/>
</pool>
<region name="TEST" refid="PROXY"/>
</client-cache>
客户端应用程序.java
public static void main(String[] args) throws Exception {
ClientCache cache = new ClientCacheFactory().set("cache-xml-file", "client-cache.xml").set("log-level", "config").create();
Region region = cache.getRegion("TEST");
region.put("key1", new MyPojo("attribute1", "attribute2"));
cache.close();
System.exit(0);
}
您可能想检查spring-data-gemfire项目,并摆脱所有样板:-)。干杯。
于 2017-07-12T10:16:50.223 回答