【问题标题】:Spring Boot Gemfire Server ConfigurationSpring Boot Gemfire 服务器配置
【发布时间】:2018-08-08 00:27:46
【问题描述】:

我正在尝试了解如何托管 Spring Boot Gemfire 服务器进程。

我找到了这个例子Spring Gemfire Server

我遇到的问题是我尝试添加到集群的服务器在我启动进程后没有显示在集群中。

以下是我正在采取的步骤:

  1. 在本地启动一个新的定位器(默认端口):gfsh>start locator --name=loc-one

  2. 我想把这个 SpringBootGemfireServer 添加到集群中:

注意我已经注释掉了嵌入式定位器启动 - 我想将它添加到已经运行的现有定位器中

    @SpringBootApplication
    @SuppressWarnings("unused")
    public class SpringGemFireServerApplication {

        private static final boolean DEFAULT_AUTO_STARTUP = true;

        public static void main(String[] args) {
           SpringApplication.run(SpringGemFireServerApplication.class, args);
    }

    @Bean
    static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
        return new PropertyPlaceholderConfigurer();
    }

    private String applicationName() {
    return SpringGemFireServerApplication.class.getSimpleName();
    }

    @Bean
    Properties gemfireProperties(
          @Value("${gemfire.log.level:config}") String logLevel,
          @Value("${gemfire.locator.host-port:localhost[10334]}") String locatorHostPort,
          @Value("${gemfire.manager.port:1099}") String managerPort) {

    Properties gemfireProperties = new Properties();

    gemfireProperties.setProperty("name", applicationName());
    gemfireProperties.setProperty("log-level", logLevel);
    //gemfireProperties.setProperty("start-locator", locatorHostPort);
    //gemfireProperties.setProperty("jmx-manager", "true");
    //gemfireProperties.setProperty("jmx-manager-port", managerPort);
    //gemfireProperties.setProperty("jmx-manager-start", "true");

    return gemfireProperties;
    }

    @Bean
    CacheFactoryBean gemfireCache(@Qualifier("gemfireProperties") Properties gemfireProperties) {

    CacheFactoryBean gemfireCache = new CacheFactoryBean();

    gemfireCache.setClose(true);
    gemfireCache.setProperties(gemfireProperties);

    return gemfireCache;
}

@Bean
CacheServerFactoryBean gemfireCacheServer(Cache gemfireCache,
        @Value("${gemfire.cache.server.bind-address:localhost}") String bindAddress,
        @Value("${gemfire.cache.server.hostname-for-clients:localhost}") String hostNameForClients,
        @Value("${gemfire.cache.server.port:40404}") int port) {

    CacheServerFactoryBean gemfireCacheServer = new CacheServerFactoryBean();


    gemfireCacheServer.setCache(gemfireCache);
    gemfireCacheServer.setAutoStartup(DEFAULT_AUTO_STARTUP);
    gemfireCacheServer.setBindAddress(bindAddress);
    gemfireCacheServer.setHostNameForClients(hostNameForClients);
    gemfireCacheServer.setPort(port);

    return gemfireCacheServer;
}

@Bean
PartitionedRegionFactoryBean<Long, Long> factorialsRegion(Cache gemfireCache,
        @Qualifier("factorialsRegionAttributes") RegionAttributes<Long, Long> factorialsRegionAttributes) {

    PartitionedRegionFactoryBean<Long, Long> factorialsRegion = new PartitionedRegionFactoryBean<>();

    factorialsRegion.setAttributes(factorialsRegionAttributes);
    factorialsRegion.setCache(gemfireCache);
    factorialsRegion.setClose(false);
    factorialsRegion.setName("Factorials");
    factorialsRegion.setPersistent(false);

    return factorialsRegion;
}

@Bean
@SuppressWarnings("unchecked")
RegionAttributesFactoryBean factorialsRegionAttributes() {

    RegionAttributesFactoryBean factorialsRegionAttributes = new RegionAttributesFactoryBean();

    factorialsRegionAttributes.setCacheLoader(factorialsCacheLoader());
    factorialsRegionAttributes.setKeyConstraint(Long.class);
    factorialsRegionAttributes.setValueConstraint(Long.class);

    return factorialsRegionAttributes;
}

FactorialsCacheLoader factorialsCacheLoader() {
    return new FactorialsCacheLoader();
}

class FactorialsCacheLoader implements CacheLoader<Long, Long> {

    // stupid, naive implementation of Factorial!
@Override
    public Long load(LoaderHelper<Long, Long> loaderHelper) throws CacheLoaderException {

        long number = loaderHelper.getKey();

        assert number >= 0 : String.format("Number [%d] must be greater than equal to 0", number);

        if (number <= 2L) {
            return (number < 2L ? 1L : 2L);
        }

        long result = number;

        while (number-- > 1L) {
            result *= number;
        }

        return result;
    }

    @Override
    public void close() {
    }
}

}

当我去gfsh&gt;connect list members

我只看到定位器。

【问题讨论】:

  • 您是否在 Spring Boot 应用程序的日志中看到任何内容?

标签: spring-boot spring-data-gemfire


【解决方案1】:

我还没有验证完整配置以检查是否还有其他问题,但我现在看到的主要问题是您似乎混淆了start-locator 属性(当成员连接到分布式系统并在成员断开连接时停止定位器)使用locators属性(系统成员使用的定位器列表,必须为分布式系统的每个成员进行一致的配置)。由于您在配置服务器时没有正确设置locators 属性,因此它无法加入现有的分布式系统,因为它不知道要连接到哪个定位器。

GemFire 使用的默认定位器端口是10334,所以你应该改变你的gemfireProperties 方法如下:

@Bean
Properties gemfireProperties(@Value("${gemfire.log.level:config}") String logLevel, @Value("${gemfire.locator.host-port:localhost[10334]}") String locatorHostPort, @Value("${gemfire.manager.port:1099}") String managerPort) {
  Properties gemfireProperties = new Properties();
  gemfireProperties.setProperty("name", applicationName());
  gemfireProperties.setProperty("log-level", logLevel);
  // You can directly use the locatorHostPort variable instead.
  gemfireProperties.setProperty("locators", "localhost[10334]");

  return gemfireProperties;
}

希望这会有所帮助。

干杯。

【讨论】:

  • 完美。我想我理解了 start-locator 过程(因为它会在同一个过程中启动一个新的定位器)——这就是我注释掉它的原因。由于我在本地(在 java 进程之外)启动了定位器并且它在 10334 上运行 - 我只是假设服务器实例会发现该定位器正在运行并加入该集群。我没有意识到我仍然必须明确设置定位器属性。
  • 是的,您始终必须在每个成员中配置集群中使用的定位器的完整列表。
  • Urizen 是正确的。这主要是因为定位器列表确定了新的对等成员将加入的分布式系统/集群,因此必须显式声明/设置。以前,GemFire/Geode 使用 mcast 网络来形成集群,但是 mcast 的问题是您最终也可能在集群中出现意外成员。所以,最好是明确的。最近的 SO 帖子详细介绍了 locatorsstart-locator 属性...stackoverflow.com/questions/51659771/…
  • 另外请注意,您上面引用的示例 (github.com/jxblum/spring-boot-gemfire-server-example) 现在是一个相当古老的示例。我的新方向是展示 SDG 2.0 中引入的基于 Annotation 的新配置模型 (docs.spring.io/spring-data/gemfire/docs/current/reference/html/…)。
  • 这是一个示例服务器,它在启用 locator-manager Spring 配置文件 (github.com/jxblum/contacts-application/blob/master/boot-example/…) 时启动具有嵌入式定位器/管理器的 CacheServer。
猜你喜欢
  • 2014-12-20
  • 2018-07-27
  • 2017-12-29
  • 2019-03-13
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
  • 1970-01-01
  • 2018-10-05
相关资源
最近更新 更多