Search code examples
cassandradatastax-java-driver

Determine replication strategy for Cassandra cluster at run time


I need to set the consistency level of a query depending on the replication strategy. A replication strategy of NetworkTopologyStrategy will mean that the insert will execute at EACH_QUORUM. A replication strategy of SimpleStrategy will mean that the insert will execute at LOCAL_QUORUM.

The session seems to have a getCluster(). Is there anyway to know the replication strategy for the Cluster object or through any other method.


Solution

  • You're on the right track. From cluster, you can getMetadata(), then Metadata.getKeyspace(String), KeyspaceMetadata.getReplication() will get you a map of replication options for a given keyspace.