【问题标题】:Get/Set PoolingOptions in Spring-Data-Cassanda (boot)在 Spring-Data-Cassanda(启动)中获取/设置 PoolingOptions
【发布时间】:2021-07-29 19:40:30
【问题描述】:

我在我的环境中使用以下依赖项:

  • spring-boot-starter-parent - v2.3.5.RELEASE
  • spring-boot-starter-data-cassandra - 相同
  • cassandra-driver-core (com.datastax.cassandra) - v3.2.0

如何在我的设置中访问在com.datastax.driver.core.PoolingOptions 中设置的连接池选项?

Spring Data Cassandra (SDC) 文档指定以下内容:

AbstractCassandraConfiguration 让您提供各种配置 选项,例如初始实体、默认查询选项、池 选项、套接字选项等等。

但我一辈子都找不到在 DS 驱动程序中设置这些池选项的位置:(

似乎 Spring 数据 Cassandra 中的 CassandraClusterFactoryBeanPoolingOptionsFactoryBean 已被删除,我不明白如何在没有这些或通过我编写的 AbstractCassandraConfiguration 扩展/实现的情况下获取 PoolingOptions 的句柄。

下面应该是支持的池选项。但是如何访问在代码中保存这些配置的 PoolingOptions bean?

Connection pooling options

cassandra.pool.heartbeat-interval-seconds - heartbeat interval in seconds.
cassandra.pool.idle-timeout-seconds - idle connection timeout in seconds.
cassandra.pool.pool-timeout-millis - timeout for acquiring connection from pool in ms.

cassandra.pool.local.core-connections-per-host - initial number of connections to each "local" host.
cassandra.pool.local.max-connections-per-host - max number of connections to each "local" host.
cassandra.pool.local.max-requests-per-connection - max number of requests per connections to "local" host.
cassandra.pool.local.new-connection-threshold - threshold to trigger new connection to "local" host.

cassandra.pool.remote.core-connections-per-host - initial number of connections to each "remote" host.
cassandra.pool.remote.max-connections-per-host - max number of connections to each "remote" host.
cassandra.pool.remote.max-requests-per-connection - max number of requests per connections to "remote" host.
cassandra.pool.remote.new-connection-threshold - threshold to trigger new connection to "remote" host.

SDC 文档中还提到:

DataStax Java Driver 4 将 ClusterSession 对象合并到一个 单个 CqlSession 对象,因此,所有与集群相关的 API 都是 删除。

为了反映配置生成器的变化, ClusterBuilderConfigurer 更名为SessionBuilderConfigurer 现在接受 CqlSessionBuilder 而不是 Cluster.Builder

感谢任何帮助。

【问题讨论】:

    标签: java spring-boot cassandra connection-pooling spring-data-cassandra


    【解决方案1】:

    我如何设法访问这些配置是通过覆盖 CassandraAutoConfiguration 类中的 cassandraDriverConfigLoader bean。

    cassandraDriverConfigLoader bean 中,Spring 配置映射到 Cassandra 驱动程序配置。

    基本上,我将自动配置中的代码复制粘贴到我的项目中,并添加了所需的配置。有一个方便的枚举,包含所有需要的配置。

    @Bean
    public DriverConfigLoader cassandraDriverConfigLoader(CassandraProperties properties,
            ObjectProvider<DriverConfigLoaderBuilderCustomizer> builderCustomizers) {
        .....
    }
    
    private Config cassandraConfiguration(CassandraProperties properties) {
        CassandraDriverOptions options = new CassandraDriverOptions();
        options.add(DefaultDriverOption.CONNECTION_MAX_REQUESTS,30000)
        ...
    }
    

    为了验证我的自定义配置是否已加载,我只是在此处放置了一个断点 DriverConfig.getDefaultProfile

    【讨论】:

      猜你喜欢
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2020-06-30
      • 2013-03-07
      相关资源
      最近更新 更多