How to publish in GemFire on all clusters / instances using ClientCache

130 Views Asked by At

We have 3 clusters (US,EU,AP) each with 2 hosts (one primary, other secondary)

Primary host of each cluster updates the secondary host in the same cluster if there is an update. But clusters do not talk with each other.

We have a single process that needs to update all 3 GemFire caches running on each cluster's primary hosts (which will eventually update secondary hosts GemFire)

cache-cluster-1.xml 
   <client-cache>
     <pool name="clientCachePool" read-timeout="90000" >
        <server host="pri1-hostname" port="1111"  />
        <server host="sec1-hostname" port="1111"  />
     </pool>
     <region>...</region>
   <client-cache>

cache-cluster-2.xml 
   <client-cache>
     <pool name="clientCachePool" read-timeout="90000" >
        <server host="pri2-hostname" port="1111"  />
        <server host="sec2-hostname" port="1111"  />
     </pool>
     <region>...</region>
   <client-cache>

cache-cluster-3.xml 
   <client-cache>
     <pool name="clientCachePool" read-timeout="90000" >
        <server host="pri3-hostname" port="1111"  />
        <server host="sec3-hostname" port="1111"  />
     </pool>
     <region>...</region>
   <client-cache>

If I try to initialize separate ClientCache i get below error - > java.lang.IllegalStateException: A connection to a distributed system already exists in this VM.

ClientCache cc1 = ccf.set("cache-xml-file", "cache-cluster-1.xml").create(); 
ClientCache cc2 = ccf.set("cache-xml-file", "cache-cluster-2.xml").create(); 
ClientCache cc3 = ccf.set("cache-xml-file", "cache-cluster-3.xml").create();

how do I publish to these three independent clusters using ClientCache?

2

There are 2 best solutions below

1
On BEST ANSWER

Close your cc1 before opening cc2, and close cc2 before opening cc3.

If you really must access data in other clusters, then: - if you need ALL of the data from regions in the other cluster, consider a WAN gateway - if you need only selected data from regions in the other cluster, consider a CQRS design where you have another process running a CQ (continuous query) against the remote cluster and updating your near cluster with the results.

0
On

You can't have more than one instance of a Cache within a single JVM, and that's because internally it works as a singleton. Moreover, connecting one single client to multiple distributed systems is highly discouraged as you can run into other issues, specifically incompatible classes definition and/or namespace conflicts.

However, GemFire/GEODE comes with an embedded mechanism to achieve this use case: Multi-site (WAN) Configuration, which basically allows you to scale horizontally between disparate, loosely-coupled distributed systems.

Hope this helps.

Best eregards