Connecting to the cluster
To get connected, you will start by creating a Cluster
reference, which you will then 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 Cluster
.
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();
Tip
You should only have one instance of Cluster
in your application for each physical cluster, as this class controls the list of contact points ...
Get Cassandra 3.x High Availability - Second Edition 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.