Announcement Announcement Module
Collapse
No announcement yet.
Multiple Gemfire DS connection using spring-data-gemfire-1.3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Gemfire DS connection using spring-data-gemfire-1.3

    Hi,

    I'm currently developing a RESTful webservice application that enable the users to connect to 2 Gemfire DS environments (PRD, DR). Access would be like this:
    http://localhost:8080/gf-web-service/PRD/accounts/1234
    http://localhost:8080/gf-web-service/DR/accounts/1234

    Using the configurations below I was only able to connect 1 GF DS instead of 2.

    How does one configure the servel.xml to be able to connect to 2 Gemfire DS cluster. Please take note that my regions are hierarchical.

    Thanks.

    --gf-web-service-servrlet.xml--
    Code:
    <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"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
        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 http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <context:component-scan base-package="company.namespace.web" />
    
        <mvc:annotation-driven />
    
        <context:property-placeholder
            location="classpath:webapp.properties" />
        
        <bean id="cachePROD" class="org.springframework.data.gemfire.CacheFactoryBean">
            <property name="properties">
                <props>
                    <prop key="log-level">config</prop>
                    <prop key="log-file">/user/tmp/cacheRunner.PROD.log</prop>
                    <prop key="cache-xml-file">gemfire-prod-cache-config.xml</prop>
    
                    <prop key="mcast-port">0</prop>
                    <prop key="socket-buffer-size">1024568</prop>
                    <prop key="license-type">production</prop>
                </props>
            </property>
        </bean>
    
        <bean id="accountDR" class="org.springframework.data.gemfire.RegionFactoryBean"
            p:cache-ref="cacheDR" p:name="/root/account" />
    
        <bean id="analyticsDR" class="org.springframework.data.gemfire.RegionFactoryBean"
            p:cache-ref="cacheDR" p:name="/root/analytics" />
    
        <bean id="cacheDR" class="org.springframework.data.gemfire.CacheFactoryBean">
            <property name="properties">
                <props>
                    <prop key="log-level">config</prop>
                    <prop key="log-file">/user/tmp/cacheRunner.DR.log</prop>
                    <prop key="cache-xml-file">gemfire-dr-cache-config.xml</prop>
    
                    <prop key="mcast-port">0</prop>
                    <prop key="socket-buffer-size">1024568</prop>
                    <prop key="license-type">production</prop>
                </props>
            </property>
        </bean>
    
        <bean id="accountDR" class="org.springframework.data.gemfire.RegionFactoryBean"
            p:cache-ref="cacheDR" p:name="/root/account" />
    
        <bean id="analyticsDR" class="org.springframework.data.gemfire.RegionFactoryBean"
            p:cache-ref="cacheDR" p:name="/root/analytics" />
    
    </beans>
    --gemfire-prod-cache-config.xml--
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cache PUBLIC
        "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
        "http://www.gemstone.com/dtd/cache6_5.dtd">
    
    <cache lock-lease="120" lock-timeout="60" search-timeout="300"
    	is-server="false" copy-on-read="false">
    
        <pool name="client-prod-pool" server-group="prod-server">
            <locator port="37000" host="prod-servername" />
        </pool>
    
        <region name="root">
            <region name="accountData">
                <region-attributes data-policy="empty" pool-name="client-prod-pool" />
            </region>
    
            <region name="analyticsRegion">
                <region-attributes data-policy="empty" pool-name="client-prod-pool" />
            </region>
        </region>
    
        <serialization-registration>
            <instantiator id="1001">
                <class-name>company.gemfire.Account</class-name>
            </instantiator>
            <instantiator id="1002">
                <class-name>company.gemfire.Analytics</class-name>
            </instantiator>
        </serialization-registration>
    	
    </cache>

    --gemfire-dr-cache-config.xml--
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cache PUBLIC
        "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
        "http://www.gemstone.com/dtd/cache6_5.dtd">
    
    <cache lock-lease="120" lock-timeout="60" search-timeout="300"
    	is-server="false" copy-on-read="false">
    
        <pool name="client-dr-pool" server-group="dr-server">
            <locator port="37000" host="dr-servername" />
        </pool>
    
        <region name="root">
            <region name="accountData">
                <region-attributes data-policy="empty" pool-name="client-dr-pool" />
            </region>
    
            <region name="analyticsRegion">
                <region-attributes data-policy="empty" pool-name="client-dr-pool" />
            </region>
        </region>
    
        <serialization-registration>
            <instantiator id="1001">
                <class-name>company.gemfire.Account</class-name>
            </instantiator>
            <instantiator id="1002">
                <class-name>company.gemfire.Analytics</class-name>
            </instantiator>
        </serialization-registration>
    	
    </cache>

  • #2
    This may be a moot point now, but I was reviewing old posts and came across this one. The short answer is you cannot do this (easily) in a single JVM process.

    In GemFire, the Cache is a singleton instance and the Spring GemFire CacheFactoryBean uses GemFire's public API (CacheFactory.getAnyInstance()) to get a reference to that Cache instance as a bean in a Spring application context. You cannot do this even with GemFire's public API, at least not without a lot of creative/custom class loading (separate ClassLoaders).

    I will say that the GemFire team is planning both an Admin and Developer REST API based on Spring Web MVC for the upcoming 7.5 release, TBD.
    Last edited by John Blum; Oct 10th, 2013, 07:38 PM.

    Comment

    Working...
    X