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:
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.
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.