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 key connection policies such as compression, failover, request routing, and retries.
While this basic example will suffice to play around with the driver locally, the Cluster
builder supports a number of additional options that are relevant for...