Connecting to the cluster

To get connected, start by creating a Cluster reference, which you will construct using a builder pattern. You will specify each additional option by chaining method calls together to produce the desired configuration, then finally, calling the build() method to initialize the Cluster instance.

Let's build a cluster that's initialized with a list of possible initial contact points:

private Cluster cluster; // defined at class level
// you should only build the cluster once per app
cluster = Cluster.builder()
  .addContactPoints("10.10.10.1", "10.10.10.2", "10.10.10.3")
  .build();

Note

You should only have one instance of Cluster in your application for each physical cluster as this class controls the list of contact points and ...

Get Cassandra High Availability now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.