Siva Samraj
Siva Samraj

Reputation: 37

Multiple Endpoints in Cassandra cluster Connection

I want to give multiple Cassandra endpoints from the config file to my Java application.

Ex: cassandra host: "host1, host2"

I tried addContactPoints(host), but it did not work. If one of the Cassandra node goes down, I don't want my application to go down.

cluster = Cluster.builder()
  .withClusterName(cassandraConfig.getClusterName())
  .addContactPoints(cassandraConfig.getHostName())
  .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(30000).setReadTimeoutMillis(30000))
  .withPoolingOptions(poolingOptions).build();

Upvotes: 2

Views: 1076

Answers (1)

Andy Tolbert
Andy Tolbert

Reputation: 11638

The java driver is resilient to one of the contact points provided not being available. Contact points are used for establishing an initial connection [*]. As long as the driver is able to communicate with one contact point, it should be able to query the system.peers and system.local table to discover the rest of the nodes in the cluster.

* They are also added to a list of initial hosts in the cluster, but typically the contact points provided map to a node in the system.peers table.

Upvotes: 3

Related Questions