【问题标题】:Datastax java driver 4.0 configuration programmatically以编程方式配置 Datastax java 驱动程序 4.0
【发布时间】:2020-06-14 13:30:57
【问题描述】:

是否仍然可以使用新的 4.0 版本配置集群(如 Datastax java 驱动程序 3.8 驱动程序版本)。或者唯一的解决方案是使用文档中的配置文件? https://docs.datastax.com/en/developer/java-driver/4.0/manual/core/configuration/

【问题讨论】:

    标签: java cassandra datastax-java-driver


    【解决方案1】:

    是的,可以通过编程方式配置驱动程序。只需遵循"" of driver documentation 部分。您只需要使用DriverConfigLoader.programmaticBuilder 定义配置加载器,然后在构建CqlSession 时使用它:

    DriverConfigLoader loader =
        DriverConfigLoader.programmaticBuilder()
            .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5))
            .startProfile("slow")
            .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(30))
            .endProfile()
            .build();
    CqlSession session = CqlSession.builder().withConfigLoader(loader).build();
    

    驱动程序有很多可用的选项,但实践表明,可以在配置文件中定义许多默认值,并且仅将加载器用于非标准的东西。

    附:最好使用驱动程序 4.5,因为它适用于 OSS 和 DSE 版本...加上许多改进,例如响应式支持等。

    【讨论】:

      猜你喜欢
      • 2018-12-20
      • 2016-11-29
      • 2016-11-29
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 2017-07-13
      • 2014-05-04
      相关资源
      最近更新 更多