通过 API 而不是使用 GFSH 创建 Gemfire 区域

Creating a Gemfire Regions Through the API instead of using GFSH

我正在尝试使用 gemfire-8.2.11.jar 中可用的 API 方法创建 gemfire 区域。为此,我创建了一个 spring 引导应用程序,在这里我使用代码创建动态 gemfire 区域,当我的应用程序启动时,它将连接到 gemfire 定位器并创建服务器。

创建 gemfire 区域后,使用命令提示符检查 gemfire 服务器。这里的问题是,如果我关闭我的应用程序,区域也会继续运行,这意味着区域名称不会持久存在(不更新 cluster.xml 中的区域详细信息)。这意味着暂时在内存中创建区域。请任何人帮助如何使区域持久化 grammatically.DO 我需要将任何属性设置为 CashFactory?。 按照下面给出的 link ,按照 gemfire 文档进行编码。

http://gemfire82.docs.pivotal.io/docs-gemfire/latest/basic_config/data_regions/create_a_region_with_API.html

    Getting Cache factory object  
     Cache cache = new  CacheFactory().set("name", "TestServer")
                               .set("locators","localhost[10334]")
                           .set("log-level", "config")
                           .create();  

    RegionFactory<Object, Object> rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
    rf.setCacheLoader(new TestCacheLoader());
    rf.setCacheWriter(new TestCacheWriter());                       
    Region<Object, Object> createdRegion = rf.create("Test");

    Need to persist grammatically created regions with my application.

为了在重启后保留区域配置,您需要使用集群配置服务,请查看Configuring and Running a Cluster for further details about this. Unfortunately in GemFire 8.2.X there was no public API to manually use this configuration service (the only way to modify cluster configuration is through internal methods or manually editing the configuration xml file while the cluster is offline) so your only option would be to use GemFire SHell. Newer versions of GemFire also have this limitation, but there's an enhancement currently being worked to make this configurable through he API directly (please have a look at Cluster Management Service了解更多详情)。

附带说明一下,考虑到您使用的 Spring Boot already, Spring Boot for Apache Geode & Pivotal GemFire 在可用性和可配置性方面取得了巨大的改进,它当然可以为您提供更大的灵活性并帮助您实现此处的目标(特别是 @EnableClusterConfiguration注解).

希望这对您有所帮助。 干杯。