简体   繁体   中英

Java Cassandra driver migration from 3 to 4

I'm currently migrating java Cassandra driver from version 3.x to 4.x and have difficulties to set our wanted config on the new driver.

I understand that the Cluster class is gone and replaced with CqlSession , just have no idea how to migrate these:

Cluster cluster = Cluster.builder()
    ...
    // how can i migrate these to be used in CqlSession ???
    .withLoadBalancingPolicy(loadBalancingPolicy)
    .withCompression(ProtocolOptions.Compression.LZ4)
    .withQueryOptions(new QueryOptions().setConsistencyLevel(LOCAL_QUORUM))
    .build();

Any idea how to move this to the new driver? Can these be somehow set on CqlSessionBuilder or do I have to use something totally different?

The configuration has been completely refactored in Java driver 4. The recommendation is to use the reference configuration file for the configurable options. For example, you would define compression options with:

datastax-java-driver {
  advanced.protocol.compression = lz4 // or snappy
}

or set the consistency level based on an execution profile:

datastax-java-driver {
  profiles {
    oltp {
      basic.request.timeout = 1000 milliseconds
      basic.request.consistency = LOCAL_QUORUM
  }
}

For details, have a look at the Java driver 4.x Upgrade Guide as a starting point. Then check out the following pages for reference:

If you're interested, check out the Java driver sample app at Astra that provides you all the code you need to get started really quickly. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM