So in the datastax doc, it states that ConsistencyLevel can be set globally through QueryOptions:
QueryOptions qo = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ALL);
I noticed that this is not a static method and returns an instance of QueryOptions. Does that mean simply calling this method won't set the default consistency level globally and I need to use the QueryOptions when connecting to the Cassandra cluster? I mean, is the following code required (to set the QueryOption
when building the Cluster
object)
cluster = Cluster.builder().addContactPoint("192.168.0.30")
.withQueryOptions(new QueryOptions()
.setConsistencyLevel(ConsistencyLevel.ONE)
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))
.build();
session = cluster.connect("demo");
My problem is that I don't have access to the code that builds the Cluster instance. Does that mean I can't set global consistency level and have to rely on setting it per Statement
?
new QueryOptions().setConsistencyLevel(ConsistencyLevel.ALL)
won't set the consistency level globally (I check the consistency level of my PreparedStatement and it'snull
). I guess you have to use the returned QueryOptions object while building your cluster object. – Crupper