How to know if connection was successfull

I have the following code:

CouchbaseClientConfiguration pConfig;
CouchbaseClient pClient;

pConfig = new CouchbaseClientConfiguration();
pConfig.Urls.Add(new Uri(""));
pConfig.Bucket = "default";

//open connection
pClient = new CouchbaseClient(pConfig);

When CouchBaseServer is down the client doesn't throws any exception or any property to check thats returns if connection was successfull.

If later the server goes up the client doesn't connect. It's necessary to create a new instance of CouchBaseClient?


1 Answer

« Back to question.

ddol -

The client is constantly communicating with the cluster and as the cluster changes, those changes are being updated in the client. If all nodes in the cluster are down, the next operation (get, set, etc) will fail with an exception.

Creating the client doesn't actually "create the connection", it initializes a connection pool internally based off your configuration which is by default a minimum of 10 connections and will grow to 20 based off usage demands. It also creates a "streaming connection" to the client which picks up in changes to the clusters (nodes added, removed, moved vbuckets, etc), which are then reflected back in client if a change is detected. When this happens the connection pool is recreated based off of the new cluster configuration.

So the answer is, no you do not need to recreate the client if a change occurs in the cluster. In fact, the client should be a long lived object that is created when the process or application starts up and destroyed when the process or application shuts down.