CouchbaseClient configuration for more than one cluster

Let’s assume I have two couchbase clusters with XDCR setup and having following nodes:


What is preferable node configuration for CouchbaseClient?

As from

The CouchbaseClient class accepts a list of URIs that point to nodes in the cluster. If your cluster has more than one node, Couchbase strongly recommends that you add at least two or three URIs to the list. The list does not have to contain all nodes in the cluster, but you do need to provide a few nodes so that during the initial connection phase your client can connect to the cluster even if one or more nodes fail.
After the initial connection, the client automatically fetches cluster configuration and keeps it up-to-date, even when the cluster topology changes. This means that you do not need to change your application configuration at all when you add nodes to your cluster or when nodes fail. Also make sure you use a URI in this format: http://[YOUR-NODE]:8091/pools. If you provide only the IP address, your client will fail to connect. We call this initial URI the bootstrap URI.

Does it mean I should add at least two or three nodes from each cluster? Or two or three node from the whole system? Does CouchbaseClient support automatic switching between clusters?

Here for 1.4:
You should open one CouchbaseClient instance per bucket per cluster. So if you want to connect to the same bucket on 2 clusters you need two CouchbaseClient objects.
And for each CouchbaseClient object you pass in n1, n2 basically.

CouchbaseClient cluster1 = new CouchbaseClient(nodes_for_c1, bucket, password);
CouchbaseClient cluster2 = new CouchbaseClient(nodes_for_c2, bucket, password);

Here is the info for the 2.0 SDK:
Every cluster needs to be treated individually, so you need one “CouchbaseCluster” reference per actual cluster. And for each of them, you should pass in more than a few so in your case 2-3 nodes.

Additionally, you should share the environment across instances to get better resource utilization. So like:

    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();
    CouchbaseCluster cluster1 = CouchbaseCluster.create(env, "", "");
    CouchbaseCluster cluster2 = CouchbaseCluster.create(env, "", "");

And then you just open the buckets from each cluster reference as needed.

Thanks for your answer! But I still have questions.
How to decide on which cluster should I open a bucket? I mean, shouldn’t XDCR be transparent for me? What if one cluster is down. How to switch to another?

Ah I know what’s going on - there is a misconception here.

XDCR is running in the background, but not transparent from a client perspective. If you connect to two different clusters, each “client” has no clue about the other cluster. That’s up to the application to perfom proper action, for example try cluster 1 and if this fails go to cluster 2.

Ok, cool!
Thank you for your explanation! Now it’s clear to me.

@notxcain great - let us know if you need anything else.

Hi Couchbase team,

1.4.4 sdk code:
ArrayList nodes = new ArrayList();
String[] uris = StringUtils.tokenizeToStringArray(couchbaseuris, “,”);
for(String uri: uris){
CouchbaseClient riClient= new CouchbaseClient(nodes, bucketName = riBucket, riPassword);
CouchbaseClient mcmAuditClient= new CouchbaseClient(nodes, bucketName = entityAuditBucket, entityAuditPassword);
CouchbaseClient specClient= new CouchbaseClient(nodes, bucketName = specBucket, specPassword);

I am migrating the above 1.4.4 sdk code implementation to the below 2.5 sdk code. Please let me know am I doing it right.
List nodes = Arrays.asList(couchbaseuris.split(",");
CouchbaseEnvironment cbEnv = DefaultCouchbaseEnvironment.builder().bootstrapCarrierEnabled(true).build();
CouchbaseCluster riClient= CouchbaseCluster.create(cbEnv, nodes);
Bucket riBucket = riClient.openBucket(bucketName, bucketPwd);
CouchbaseCluster mcmAuditClient= CouchbaseCluster.create(cbEnv, nodes);
Bucket mcmBucket = mcmAuditClient.openBucket(bucketName, bucketPwd);
CouchbaseCluster specClient= CouchbaseCluster.create(cbEnv, nodes);
Bucket specBucket = specClient.openBucket(bucketName, bucketPwd);

It might be best if you don’t post something loosely related on a very old (4y!) thread. The Start Using documentation covers what you’re looking for. Check that and if you have trouble, post a new topic with what you tried and what’s not working please.