java.lang.IllegalStateException When Connecting One GemFire Cluster to Another as a Client
search cancel

java.lang.IllegalStateException When Connecting One GemFire Cluster to Another as a Client

book

Article ID: 443298

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

When attempting to establish a connection from one GemFire cluster (Cluster 2) to another (Cluster 1) using client-server logic within a server process, the following exception is thrown:

java.lang.IllegalStateException: A client cache can not be created because a non-client cache already exists.


This commonly occurs when executing code like the following inside a GemFire function on a server:

var client = new ClientCacheFactory()
    .addPoolLocator("localhost", 10334)
    .create();

 

Environment

GemFire

Cause

GemFire clusters cannot connect in a client-server hierarchy. There is a fundamental technical limitation where a GemFire server process (peer cache) cannot initialize a ClientCache within the same JVM.

Since the GemFire cache is a singleton, once the server/peer cache is initialized, any attempt to create a client cache via ClientCacheFactory will result in an IllegalStateException because a non-client cache already exists in that process.

Resolution

To interconnect two GemFire clusters or consume data across clusters, use one of the following supported methods:

1. WAN Replication

Interconnect GemFire clusters using WAN Replication. This is the only supported method for cluster-to-cluster communication, utilizing Gateway Senders and Gateway Receivers to synchronize data.

2. Dedicated Client for Continuous Queries (CQ)

Continuous Queries (CQ) are only supported on the client-side. If you need to establish a CQ to GemFire Cluster 1, the consumer (logic in "GemFire 2") must be a pure GemFire client application. It cannot be a GemFire server instance or a process running inside a GemFire server cluster.