Reputation: 67
I'm new to Cassandra I want to connect to Cassandra through Java client as Cassandra api.I can connect to Cassandra with my java code by using datastax as weel as jdbc drivers by giving the node details in my java code. Now I want to connect to Cassandra cluster where I have 4 nodes in cluster,I want to connect to the Cassandra cluster nodes with out giving the node details in code and need to get connection when 1 node is down in cluster it should get connect to the next node in the cluster,so where to mention my node details in my code when Im using datastax drivers. Can any one help me to do this..It will helps me alot Thanks in advance
Upvotes: 0
Views: 1800
Reputation: 67
I was able to connect to cassandra cluster when one of my node is down from cluster can able to connect to other node in the cluster and can achieve the load balance also, below is the connection I used and got connected.
cluster = Cluster
.builder()
.addContactPoints("192.1.1.1","192.1.1.2")
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(
new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().build()))
.build();
Upvotes: 0
Reputation: 156
Check out this Load Balancing page.
Cassandra uses gossip to stay current on the status of all other nodes. You can connect to one and it'll know all the others and load balance as directed. Basically if the node you were testing on before is apart of this new cluster your old code should work just fine.
Upvotes: 0