This policy is datacenter aware and routes queries to the local nodes first. There are two constructors for instantiating this class:
- DCAwareRoundRobinPolicy(String localDc): This specifies the name of the local data center
- DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc): This can configure the number of nodes to try in a remote data center
To use this policy, use the withLoadBalancingPolicy() method to set the LB policy, as follows:
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1") .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder() .withLocalDc("localDc") .withUsedHostsPerRemoteDc(2) .allowRemoteDCsForLocalConsistencyLevel() .build()).build();