Question

Suppose I have Gemfire locator & cacheserver processes already running in my target deployment environments. The target deployment environment uses a client-server topology.

I have a Spring 3.1 MVC application which wants to use the Gemfire cache. I'm using Spring Data Gemfire 1.2.2 and Gemfire 6.6.1

So I've added the following to my spring.xml

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

<gfe:cache id="gemfireCache" properties-ref="gemfire-props"/>
<gfe:replicated-region id="myCacheRegion" cache-ref="gemfireCache">
    <gfe:cache-listener>
        <ref bean="gemfireCacheLogListener"/>
    </gfe:cache-listener>
    <gfe:entry-ttl timeout="${gemfire.myCacheRegion.ttl}" action="DESTROY"/>
</gfe:replicated-region>

<bean id="gemfireCacheLogListener" class="org.awong.GemfireCacheLogListener"></bean>

<bean id="cacheManager" class="org.springframework.data.gemfire.support.GemfireCacheManager"
    p:cache-ref="gemfireCache">
    <property name="regions">
        <set>
            <ref bean="myCacheRegion"/>
        </set>
    </property>
</bean>

Assume that the external JAR dependencies have all been defined correctly in, say, Maven. Assume also that I have a properties file loaded that defines the property values referenced above. The locators property is defined to use the IPs and ports of the Gemfire locators that have already been started.

I believe this ought to be good enough so that I can annotate beans in my MVC application with @Cacheable. I expect these configurations to start up a locator in the application server to connect to the Gemfire grid, add myCacheRegion to the Gemfire cacheserver, and then the cacheManager ought to be able to use the new cache region.

I am getting BeanCreationExceptions which are caused by the failure to connect to the locator when Spring starts up:

4-Mar-2013 16:02:08.750 SEVERE org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
 org.springframework.beans.factory.BeanCreationException:
 [rest of stack trace snipped out]
 nested exception is com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service.  Operation either timed out or Locator does not exist.
Configured list of locators is "[hostnameOfLocator<v0>:portOfLocator]".

But when I deploy to the target environments the Gemfire beans fail to be created because the locator processes cannot connect. What am I missing?

Était-ce utile?

La solution

It's hard to say without seeing the logs. Your configuration looks ok. What errors are you seeing in these processes and in locator.log?

I expect these configurations to start up a locator in the application server.

These configurations do not start up a locator, only connect to the configured locators. But you state earlier the locators are already started. Also mcast-port should always be 0 when using locators.

A common problem is the gemfire.jars must all be at the same version. SDGF 1.2.2 depends on gemfire 7.0. If you are using gemfire 6.6.1 you need to exclude the gemfire dependency from spring-data-gemfire in your pom.

The target deployment uses a client server topology.

This configuration is for peer-to-peer. It should still work, but if you have existing cache-servers you may want this to be configured as a client. Is this region be a replica of on on the servers or local data only? Note, if you simply need @Cacheable, you don't need to connect to a grid. A standalone embedded cache will work fine.

Autres conseils

You may try to configure locators pool, e.g.:

<gfe:pool id="locatorPool">
    <gfe:locator host="host1" port="port1"/>
    <gfe:locator host="host2" port="port2"/>
</gfe:pool>

And then link your cache to this pool:

<gfe:cache id="gemfireCache" pool-name="locatorPool"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top