I am using Spring Data for Apache Geode for a Spring Boot app that uses a remote Apache Geode server. To set up local Regions I am using @Configuration class like:
@Configuration
public class GeodeConfig {
public static Region<String, String> myRegion;
@Bean("setupMyRegion")
public Region<String, String> setupMyRegion(GemFireCache cache) {
Region<String, String> r = cache.getRegion("myRegion");
myRegion = r;
return r;
}
}
This enables me to put and get data with the Region.
When I register interest in subscribing to a key, the subscription is setup with scope=LOCAL like this:
org.apach.geode.inter.cache.LocalRegion 4439 logKeys: org.apache.geode.internal.cache.LocalRegion[path='/myRegion';scope=LOCAL';dataPolicy=NORMAL; concurrencyChecksEnabled] refreshEntriesFromServerKeys count=1 policy=KEYS_VALUES
and I guess that I want to set it up as a CACHING_PROXY so that later, on subscribing to events in the Region, the local subscription will see the server Region events.
I've set subscriptionEnabled=TRUE for the @ClientCacheApplication and I am trying to set
clientRegionShortcut = ClientRegionShortcut.CACHING_PROXY
I don't know where to do this. I've tried the @EnableClusterDefinedRegions annotation but the Region is still being set to local.
If I try to create a Region Factory from the GemFireCache it gives me an error that the method createClientRegionFactory(ClientRegionShortcut) is "undefined" for the type GemFireCache.
THANKS
Generally, it is bad practice to use the Apache Geode API directly to configure beans in a Spring context. For example...
Or using:
Both approaches above are not recommended!
Spring Data for Apache Geode (SDG) contains specific Spring
FactoryBeansto do the same thing. For instance, the SDGClientRegionFactoryBean.You would use the
ClientRegionFactoryBeanin your Spring application configuration as follows:There are SDG
FactoryBeansfor different types of Geode objects, such a [client]Regions,Indexes,DiskStores,GatewayReceivers,GatewaySenders, etc.These
FactoryBeansare essential in ensuring the the "lifecycle" of the Geode objects (e.g.Region(s)) are properly synced to the lifecycle of the Spring container. By forgoing the use of SDG'sFactoryBeansyou are effectively ignoring the lifecycle coordination provided by the Spring container and custom (framework)FactoryBeans, and are therefore responsible for the lifecycle of the Geode objects themselves when using Geode's API direct in Spring config. This is one of the primary reasons SDG's exists in the first place.A "client"
Regionmust be a*PROXY(e.g.PROXYorCACHING_PROXY) in order to enable subscriptions and receive interesting events from servers for that Region. This is because the Geode cluster (servers) maintain a subscription queue for clients when they connect, which contain events that the client has expressed interests in receiving.For
*PROXYclientRegions, this also means that the clientRegionmust have a corresponding server-side, peer cacheRegionby the same name.You can simplify Region creation in general, and client Region creation in particular, by using SDG's Annotation-based configuration model, and specifically,
@EnableEntityDefinedRegionsor@EnableCachingDefinedRegions.For instance:
Of course, this assumes you have defined application domain model entity classes, such as:
The
ClientRegionFactoryBeanwould be typed accordingly:ClientRegionFactoryBean<Long, SomeEntity>.See the SDG Annotation-based configuration model documentation for more details, and specifically Annotation configuration covering Region definitions.
The
@EnableClusterDefinedRegionsannotation defines client-sideRegionsfor all existing server-side (cluster)Regionsto which the client connects.For example, if you start a cluster in Gfsh as follows:
And then connect a Spring Boot, Apache Geode
ClientCacheapplication to this cluster by using the following Geode configuration:Then the Spring Boot, Apache Geode
ClientCacheapplication would have 2 Spring configured client Region beans with names "Example" and "AnotherExample" both of type,CACHING_PROXY.If there are NO server-side Regions presently in the cluster, then the
@EnableClusterDefinedRegionswould not define any client-side Regions.Anyway, I hope this makes sense and helps!
Cheers!