GemFire缓存客户端可以在服务器上创建区域吗?

时间:2017-01-05 21:07:25

标签: java spring gemfire spring-data-gemfire geode

我有一个客户端/服务器拓扑方案。

在本地运行一个Locator和两个服务器的简单集群,不同的JVM进程,服务器在启动时没有使用以下配置创建区域:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:gfe="http://www.springframework.org/schema/gemfire"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<util:properties id="gemfireProperties">
    <prop key="name">${gemfire.server.name}</prop>
    <prop key="mcast-port">${gemfire.server.mcast-port}</prop>
    <prop key="log-level">${gemfire.server.log-level}</prop>
    <prop key="locators">${gemfire.server.locators}</prop>
</util:properties>

<gfe:cache properties-ref="gemfireProperties" use-cluster-configuration="true"/>

<gfe:cache-server auto-startup="true" bind-address="${gemfire.server.bind-address}"
                  host-name-for-clients="${gemfire.server.hostname-for-clients}"
                  port="${gemfire.server.port}"
                  max-connections="${gemfire.server.max-connections}"/>

然后,我正在运行具有以下配置的客户端:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:gfe="http://www.springframework.org/schema/gemfire"
   xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
                        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<beans>
    <gfe:client-cache id="gemfireClientCache" pool-name="gemfireConnectionPool" ready-for-events="true"/>

    <gfe:pool id="gemfireConnectionPool" subscription-enabled="true">
        <gfe:locator host="localhost" port="10334"/>
    </gfe:pool>

    <gfe:client-region id="MYREGION"
                       shortcut="PROXY"
                       key-constraint="java.lang.String"
                       value-constraint="MYPOJO"
                       cache-ref="gemfireClientCache"
                       pool-name="gemfireConnectionPool"/>

</beans>

Spring Boot应用程序启动没有任何问题,但我发现以下日志很奇怪:

[info 2017/01/05 20:37:56.103 WET <main> tid=0x1] Running in local mode since mcast-port was 0 and locators was empty.

虽然我可以看到Pulse中的所有集群成员,但服务器没有&#34; MYREGION&#34;区域。所以,我想知道,可以缓存客户端实际上在服务器上创建区域,还是只能#34;使用&#34;现有地区?

Pivotal文档确实有一个部分用于&#34;动态创建区域&#34;但我还没有这样做,因为我失去了分区。

由于

2 个答案:

答案 0 :(得分:1)

EnableClusterConfiguration可以为您执行此操作->选中此项-https://docs.spring.io/spring-data/gemfire/docs/current/reference/html/#bootstrap-annotation-config

考虑以下配置中表达的力量:

Spring ClientCache应用程序

@SpringBootApplication
@ClientCacheApplication
@EnableCachingDefinedRegions
@EnableEntityDefinedRegions
@EnableIndexing
@EnableGemfireCaching
@EnableGemfireRepositories
@EnableClusterConfiguration
class ClientApplication { .. }

您立即获得一个带有Pivotal GemFire ClientCache实例,Spring Data Repositories,带有Pivotal GemFire作为缓存提供程序的Spring Cache Abstraction的Spring Boot应用程序(区域和索引不仅在客户端上创建,而且被推送到服务器中的服务器上)群集)。

答案 1 :(得分:0)

  

所以,我想知道,缓存客户端是否可以在服务器上实际创建区域,还是只能“使用”现有区域?

OOTB,没有。默认情况下,缓存客户端仅使用现有的区域

但是,可以使用GemFire功能在GemFire群集中的另外一个GemFire服务器上动态创建 Region 。这正是 Gfsh 所做的。

不过,还有很多事情需要考虑......

  1. 应该创建 Region 的“类型”(即PARTITION,REPLICATE等),这不仅仅是基于客户区域吗?

  2. 群集中的哪些服务器实际上应该托管区域

  3. 这可以通过客户端用于在服务器上创建相应的 Region 的GemFire Pool来限制,这必须通过客户端的Function执行来完成,如前所述。

    如果(特定)GemFire池配置了特定服务器“组”,则只有该“组”中群集中的服务器才能创建 Region

    1. Region 应具有的数据策略类型外,还有许多其他配置设置和注意事项(一致性,逐出/过期策略,安全性,事务范围,序列化(特别是如果多语言客户端)在客户可以随意拥有一台服务器或一组服务器创建一些任意的 Region 之前,需要对其进行正确的称重。想想.NET)等等。
    2. 当您开始将其与其他内容(如群集配置)混合使用时,您可能会很快遇到问题(例如,名为 Regions 的冲突)。

      虽然这在开发期间是一个有用的功能,但我甚至考虑在SDG中使用新的Annotation-based configuration model,再加上SD Repository抽象使用的(新)映射Region annotations,特别是在客户端上使用 new @ClientRegion注释来注释应用程序域对象(实体),这在生产环境中可能是不可取的。

      希望这有帮助! 约翰