1

我正在开发一个需要 Pivotal GemFire 的项目。我找不到有关如何使用 Spring Boot 配置 gemFire 的正确教程。

我创建了一个分区区域,我也想配置定位器,但我只需要服务器端配置,因为客户端由其他人处理。

我对 Pivotal GemFire 完全陌生,真的很困惑。我曾尝试创建一个cache.xml,但后来不知何故创建了一个cache.out.xml,并且存在很多问题。

4

2 回答 2

2

@Priyanka-

最好的起点是 spring.io 上的指南。具体来说,看看...

"使用 GemFire 访问数据"

还有...

使用 GemFire 缓存数据”,以及...

"使用 REST 访问 GemFire 数据"

但是,这些指南主要关注“客户端”应用程序问题、“数据访问”(通过 REST)、“缓存”等。

尽管如此,您仍然可以使用Spring Data GemFire(甚至在Spring Boot应用程序中)来配置 GemFire 服务器。我有很多这样的例子。一个特别...

Spring Boot GemFire 服务器示例

此示例演示如何将Spring Boot应用程序引导为 GemFire 服务器(技术上,集群中的对等节点)。此外,GemFire 属性是指定的Spring配置,并且可以使用Spring 的常规约定(属性占位符、SpEL 表达式)来配置这些属性,就像这样......

https://github.com/jxblum/spring-boot-gemfire-server-example/blob/master/src/main/java/org/example/SpringBootGemFireServer.java#L59-L84

这种特殊的配置使 GemFire 服务器成为“GemFire 管理器”,可能带有嵌入式“定位器”(由start-locatorGemFie 属性指示,不要与允许我们的节点加入和“现有”集群的“定位器”GemFire 属性混淆)以及一个GemFire CacheServer来服务 GemFire 缓存客户端(带有ClientCache)。

此示例创建一个“Factorials”区域,使用CacheLoader此处定义)来填充缓存未命中的“Factorials”区域。

由于此示例在Spring Boot GemFire Server 应用程序进程中启动了嵌入式 GemFire 管理器,因此您甚至可以使用Gfsh连接到它,就像这样......

gfsh> connect --jmx-manager=localhost[1099]

然后你可以在“Factorial”区域上运行“gets”来查看它计算你给它的数字键的阶乘。

要查看更高级的配置,请查看我的其他存储库,特别是Contacts Application RI(此处)。

希望这可以帮助!

-约翰

于 2017-01-13T23:45:37.923 回答
1

好吧,我遇到了同样的问题,让我与您分享一下对我有用的方法,在这种情况下,我使用 Spring Boot 和 Pivotal GemFire 作为缓存客户端。

  1. 安装并运行 GemFire
  2. 阅读15 分钟快速入门指南
  3. 创建一个定位器(我们称之为locator1)和一个服务器(server1)和一个区域(region1
  4. 转到您启动“ Gee Fish ”(gfsh)的文件夹,然后转到定位器的文件夹并打开日志文件,在该文件中您可以获取定位器正在使用的端口。

现在让我们看看 Spring Boot 方面:

  1. 在您使用该main方法的应用程序中添加@EnablegemFireCaching注释
  2. 在要缓存的方法(无论它在哪里)中,添加@Cacheable("region1")注释。
  3. 现在让我们为缓存创建一个配置文件:

    //这是我的工人阶级

    @Configuration 公共类 CacheConfiguration {

    @Bean
    ClientCacheFactoryBean gemfireCacheClient() {
        return new ClientCacheFactoryBean();
    }
    
    @Bean(name = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME)
    PoolFactoryBean gemfirePool() {
    
        PoolFactoryBean gemfirePool = new PoolFactoryBean();
    
        gemfirePool.addLocators(Collections.singletonList(new ConnectionEndpoint("localhost", HERE_GOES_THE_PORT_NUMBER_FROM_STEP_4)));
        gemfirePool.setName(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
        gemfirePool.setKeepAlive(false);
        gemfirePool.setPingInterval(TimeUnit.SECONDS.toMillis(5));
        gemfirePool.setRetryAttempts(1);
        gemfirePool.setSubscriptionEnabled(true);
        gemfirePool.setThreadLocalConnections(false);
    
        return gemfirePool;
    }
    
    @Bean
    ClientRegionFactoryBean<Long, Long> getRegion(ClientCache gemfireCache, Pool gemfirePool) {
        ClientRegionFactoryBean<Long, Long> region = new ClientRegionFactoryBean<>();
        region.setName("region1");
        region.setLookupEnabled(true);
        region.setCache(gemfireCache);
        region.setPool(gemfirePool);
        region.setShortcut(ClientRegionShortcut.PROXY);
    
        return region;
    }
    

    就是这样!,也不要忘记序列化(implements Serializable)正在缓存的类(您的缓存方法返回的类)

于 2018-01-04T19:15:13.590 回答