Load-balancing policy

As the name implies, the driver forwards queries to hosts based on the load-balancing policy chosen. Usually, this distributes the queries evenly amongst the nodes in the cluster. Java driver provides several load-balancing policies. You can create your own load-balancing policies as well.

To set a load-balancing policy, you will have to use the withLoadBalancingPolicy() method of the Cluster.Builder object:

Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withLoadBalancingPolicy(LoadBalancingPolicy policy).build();

Get Learning Apache Cassandra - 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.