Java GemFire缓存客户端能否在服务器上创建区域?

Java GemFire缓存客户端能否在服务器上创建区域?,java,spring,gemfire,spring-data-gemfire,geode,Java,Spring,Gemfire,Spring Data Gemfire,Geode,我有一个客户机/服务器拓扑方案 在本地运行一个由一个定位器和两个服务器组成的简单集群,使用不同的JVM进程,这些服务器在启动时没有使用以下配置创建的区域: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:gfe="http://www.springframework.org/schema/gemfire" x

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

在本地运行一个由一个定位器和两个服务器组成的简单集群,使用不同的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>

${gemfire.server.name}
${gemfire.server.mcast端口}
${gemfire.server.log level}
${gemfire.server.locators}

然后,我使用以下配置运行客户端:

<?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.
[info 2017/01/05 20:37:56.103湿tid=0x1]在本地模式下运行,因为mcast端口为0,定位器为空。
虽然我可以在Pulse中看到所有集群成员,但服务器没有“MYREGION”区域。所以,我想知道,缓存客户端是否真的可以在服务器上创建区域,还是只能“使用”现有区域

关键文档中确实有“动态创建区域”一节,但我还没有这样做,因为我丢失了分区

谢谢

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

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

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

但是,还有很多事情要考虑……<
  • 应该创建哪种“类型”的区域(即分区、复制等),这种区域不容易单独基于客户机区域

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

  • 这可能受到客户端用于在服务器上创建相应区域的GemFire池的限制,如前所述,必须通过从客户端执行函数来完成

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

  • 除了该区域应具有的数据策略类型外,还有许多其他配置设置和注意事项(一致性、逐出/过期策略、安全性、事务范围、序列化(特别是在涉及多语言客户端的情况下…想想.NET)等)在客户机可以任意让一个服务器或一组服务器创建任意区域之前,需要对这些区域进行适当的权衡
  • 当您开始将它与其他东西(如集群配置)混合使用时,您可能会很快遇到问题(例如,命名区域冲突)

    虽然这是开发过程中的一个有用功能,我甚至正在考虑SDG中的新功能,以及SD存储库抽象使用的(新)映射,特别是在客户端上,使用新的
    @ClientRegion
    注释来注释应用程序域对象(实体),这在生产环境中可能不可取

    希望这有帮助!
    John

    EnableClusterConfiguration可以为u-->执行此操作检查-

    考虑以下配置中表示的功率:

    <?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>
    
    SpringClientCache应用程序

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

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

    谢谢你的邀请feedback@JohnBlum如何动态创建子区域?我有一个用例:所有帐户的区域。我的应用程序接收与不同帐户关联的事务。如果不存在子区域,我是否可以动态创建子区域(使用区域过期TTL)?每个子区域映射到一个帐号。在子区域内,我将事务ID作为键,事务内容作为值。当我使用事务时,我将使用一个帐户的所有事务。Gemfire可行吗?嗨,Prashanth,我试过这个注释,得到了下面的错误-