获取/设置Spring-Data-Cassanda中的PoolingOptions(启动) [英] Get/Set PoolingOptions in Spring-Data-Cassanda (boot)

查看:46
本文介绍了获取/设置Spring-Data-Cassanda中的PoolingOptions(启动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  • Spring-Boot-starter-Parent-v2.3.5版本
  • Spring-Boot-starter-data-Cassandra-ame
  • Cassandra-Driver-core(com.datastax.cassandra)-v3.2.0

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

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

AbstractCassandraConfiguration允许您提供各种配置 选项,如初始实体、默认查询选项、池化 选项、插座选项等。

但我无论如何也找不到在DS驱动程序中设置这些池化选项的位置:(

看起来Spring data中的CassandraClusterFactoryBeanPoolingOptionsFactoryBeanCassandra已被移除,我不知道如何在没有它们的情况下或通过我编写的AbstractCassandraConfiguration扩展/实现来获得PoolingOptions的句柄。

以下是受支持的池化选项。但是,如何访问代码中包含这些配置的PoolingOptionsBean呢?

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文件中还提到:

ClusterSession对象合并到一个 因此,所有与集群相关API都是 已删除。

为了反映配置构建器中的更改, ClusterBuilderConfigurer已重命名为SessionBuilderConfigurer 现在接受CqlSessionBuilder而不是Cluster.Builder

感谢任何帮助。

推荐答案

我设法访问这些配置的方式是通过覆盖CassandraAutoConfiguration类中的cassandraDriverConfigLoaderBean。

此处,在cassandraDriverConfigLoaderBean中,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

处设置了一个断点

这篇关于获取/设置Spring-Data-Cassanda中的PoolingOptions(启动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆