【问题标题】:started geode spring boot and save to remote region but failed to start bean gemfireClusterSchemaObjectInitializer启动 geode spring boot 并保存到远程区域但无法启动 bean gemfireClusterSchemaObjectInitializer
【发布时间】:2019-12-23 18:37:26
【问题描述】:

使用简单的客户端应用程序,创建对象和对象存储库,连接到 Geode 集群,然后运行 ​​@Bean ApplicationRunner 将一些数据放到远程区域。

@ClientCacheApplication(name = "Web", locators = @Locator, logLevel = "debug", subscriptionEnabled = true)
@EnableClusterDefinedRegions
@EnableClusterConfiguration(useHttp = true)
@EnablePdx
public class MyCache {

private static final Logger log = LoggerFactory.getLogger(MyCache.class);

@Bean
ApplicationRunner StartedUp(MyRepository myRepo){       
    log.info("In StartedUp");

    return args -> {            
    String guid = UUID.randomUUID().toString().substring(0, 8).toUpperCase();
    MyObject msg = new MyObject(guid, "Started");

    myRepo.save(msg);

    log.info("Out StartedUp");
    };
}   

“保存”放置失败并显示

org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect

【问题讨论】:

  • 这个异常实际上取决于你最初是如何启动 GemFire 或 Geode 服务器的。

标签: spring-data-gemfire


【解决方案1】:

Problem creating region and persist region to disk Geode Gemfire Spring Boot 提供帮助。问题是@EnableClusterConfiguration(useHttp = true)

这个注解使远程集群看起来是一个本地主机。如果我完全删除它,那么 put 就可以了。

如果只删除useHttp = true,则会出现另一个错误:

org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.apache.geode.cache.client.ServerOperationException: remote server on #.#.#.#(Web:9408:loner)### The function is not registered for function id CreateRegionFunction

【讨论】:

  • 对,没有useHttp=true、SDG,特别是@EnableClusterConfiguration 注解要求集群中的服务器已经使用基于注解的配置模型使用SDG(或SBDG)进行配置和引导.
  • 如果您使用 Gfsh 来配置/引导您的服务器集群(在大多数情况下推荐),那么您必须配置 useHttp=true。通过使用 Gfsh,Locator 中的管理 REST API 应该可用(只有 GemFire/Geode 的完整分发才会出现这种情况)。如果您在启动时在 GemFire/Geode Locator 中调整了嵌入式 HTTP 服务/服务器(即 Jetty)的主机/端口,则可以在 @EnableClusterConfiguration 注释上指定 host 和/或 port 属性。
【解决方案2】:

简而言之,SDG @EnableClusterConfiguration 注释(详细信息可用 here)允许从客户端推送在客户端(即 Spring [Boot] Data、GemFire/Geode 应用程序)上定义和声明的配置元数据到集群(GemFire/Geode 服务器)。

我说“启用”是因为它取决于客户端配置元数据(即您显式或隐式定义/声明的 Spring bean 定义)。显式配置是您使用 bean 定义定义的配置(在 XML 中,或带有 @Bean 的 JavaConfig 等)。隐式配置是自动配置或使用@EnableEntityDefinedRegions@EnableCachingDefinedRegions等SDG注解。

默认情况下,@EnableClusterConfiguration 注释假定 GemFire 或 Geode 服务器集群已使用 Spring 进行配置和引导,特别是使用 SDG Annotation configuration model。当 GemFire 或 Geode 服务器配置并使用 Spring 引导时,SDG 继续注册一些提供的、罐装的 GemFire 函数,@EnableClusterConfiguration 注释调用(默认情况下和...)作为后备.

注意:请参阅 SBDG 参考文档中的 appendix,了解如何使用 Spring 配置和引导 GemFire 或 Geode 服务器,甚至是服务器集群。与使用 Gfsh 相比,这无疑简化了本地开发和调试。您可以进行各种有趣的组合:带有 Spring 服务器的 Gfsh Locator、带有 Gfsh 和 Spring 服务器的 Spring [embedded|standalone] Locator 等。

大多数时候,用户在客户端使用 Spring 和 Gfsh 来(部分)配置和引导他们的集群(服务器)。在这种情况下,Spring 通常不在服务器的类路径中,并且我上面提到的“提供的、固定的”函数不存在并自动注册。在这种情况下,您必须依靠 GemFire/Geodes 内部的管理 REST API(我知道一两件事,;-) 将配置元数据从客户端发送到服务器/集群。这就是为什么必须将@EnableClusterConfiguration 注释上的useHttp 属性设置为true

这就是您看到异常的原因...

org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; 

nested exception is org.apache.geode.cache.client.ServerOperationException: remote server on #.#.#.#(Web:9408:loner)### 
    The function is not registered for function id CreateRegionFunction

CreateRegionFunction 是 SDG 提供的开箱即用的预制函数,但仅当 Spring 用于配置和引导集群中的服务器时。

这通常适用于 CI/CD 环境,尤其是我们自己的测试基础架构,因为我们通常没有完整安装的 Apache Geode 或 Pivotal GemFire 可用于在这些环境中进行测试。对于 1,这些工件必须可以从 Maven Central 等工件存储库中解析。 Apache Geode(尤其是)Pivotal GemFire 发行版不是。 JAR 是,但完整的发行版不是。总之……

希望到目前为止,所有这些都是有意义的。

如果可以的话,我确实有一个建议。

鉴于您的应用程序类定义以...开头

@ClientCacheApplication(name = "Web", locators = @Locator, 
    logLevel = "debug", subscriptionEnabled = true)
@EnableClusterDefinedRegions
@EnableClusterConfiguration(useHttp = true)
@EnablePdx
public class MyCache { ... }

我强烈建议直接使用 Spring Boot for Apache Geode(和 Pivotal GemFire),即 SBDG,直接代替 SDG。

然后您的应用程序类可以简化为:

@SpringBootApplication
@EnableClusterAware
@EnableClusterDefinedRegions
public class MyCache { ... }

然后您可以使用 Spring Boot application.properties 文件将一些硬编码配置设置外部化:

spring.application.name=Web
spring.data.gemfire.cache.log-level=debug
spring.data.gemfire.pool.subscription-enabled=true

注意:@EnableClusterAware@EnableClusterConfiguration 的更强大和更强大的扩展。查看更多详细信息here

这里有一些资源可以帮助您:

一般而言,基于 SDG、SSDG 和 STDG 的 SBDG 是 Apache Geode 和 Pivotal GemFire(或现在的 Pivotal Cloud Cache)所有事物的首选/推荐起点Spring .

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 2015-05-10
    相关资源
    最近更新 更多