RoundRobinPolicy

This is the default load-balancing policy. This is a straightforward implementation and chooses hosts in a round robin fashion to execute queries. This implementation is not datacenter aware. If a host fails in a query, the next one in the round robin is used.

Suppose you have three hosts in a cluster. Your query execution sequence could look like this:

  • Query1: host1, host2, host3
  • Query2: host2, host3, host1
  • Query3: host3, host1, host2

To use this policy, create a Cluster object as follows:

Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withLoadBalancingPolicy(new RoundRobinPolicy()).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.