简体   繁体   English

Java Cassandra驱动从3迁移到4

[英]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.我目前正在将 java Cassandra 驱动程序从版本 3.x 迁移到 4.x,并且难以在新驱动程序上设置我们想要的配置。

I understand that the Cluster class is gone and replaced with CqlSession , just have no idea how to migrate these:我知道Cluster class 已经消失并替换为CqlSession ,只是不知道如何迁移这些:

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?这些可以以某种方式在CqlSessionBuilder上设置,还是我必须使用完全不同的东西?

The configuration has been completely refactored in Java driver 4. The recommendation is to use the reference configuration file for the configurable options.在 Java 驱动程序 4 中已对配置进行了完全重构。对于可配置选项,建议使用参考配置文件 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.有关详细信息,请查看Java 驱动程序 4.x 升级指南作为起点。 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.如果您有兴趣,请查看Astra 的 Java 驱动程序示例应用程序,它为您提供快速入门所需的所有代码。 Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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