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

Can GemFire cache clients create Regions on servers?

我有一个 client/server 拓扑方案。

运行一个简单的集群,由一个 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 启动应用程序没有任何问题,但我发现以下日志很奇怪:

[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 中看到所有集群成员,但服务器没有 "MYREGION" 区域。所以,我想知道,缓存客户端是否真的可以在服务器上创建区域,或者它们只能 "use" 现有区域?

Pivotal 文档确实有 "Dynamically create regions" 的部分,但我不会那样做,因为我失去了分区。

谢谢

So, I'm wondering, can cache-clients actually create regions on servers or can they only "use" existing regions?

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

但是,可以使用 GemFire 函数在 GemFire 集群中的多个 GemFire 服务器上动态创建 Region。这正是 Gfsh 所做的。

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

  1. 应该创建 Region 的 "type"(即 PARTITION、REPLICATE 等),这不容易仅基于客户端区域?

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

这可以通过客户端使用哪个 GemFire 池在服务器上创建相应的 Region 来限制,这必须像以前一样从客户端执行函数来完成提到。

如果(特定的)GemFire 池配置有特定服务器 "group",则只有该 "group" 中的集群中的服务器才能创建该 区域.

  1. 除了 Region 应具有的数据策略类型外,还有许多其他配置设置和注意事项(一致性、eviction/expiration 策略、安全性、事务范围、序列化(特别是如果涉及多语言客户端......想想.NET)等),在客户端可以任意地让一个服务器或一组服务器创建一些任意的 Region[=50 之前需要正确权衡=].

当您开始将其与 Cluster Config 等其他东西混合使用时,您可以 运行 很快解决问题(例如冲突命名 Regions).

虽然这是开发过程中的一个有用功能,我什至正在考虑用于 SD 存储库抽象所使用的新 Annotation-based configuration model in SDG, coupled with the (new) mapping Region annotations,特别是在具有 new[ 的客户端上=66=] @ClientRegion 注释用于注释应用程序域对象(实体),这在生产环境中可能不可取。

希望对您有所帮助! 约翰

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 { .. }

您立即获得一个 Spring 启动应用程序,其中包含 Pivotal GemFire ClientCache 实例、Spring 数据存储库、Spring 的缓存抽象,其中 Pivotal GemFire 作为缓存提供程序(其中区域并且索引不仅在客户端创建,而且推送到集群中的服务器)。