公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

本文介绍了获取/设置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中的CassandraClusterFactoryBean和PoolingOptionsFactoryBeanCassandra已被移除,我不知道如何在没有它们的情况下或通过我编写的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文件中还提到:

将Cluster和Session对象合并到一个
因此,所有与集群相关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(启动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

分享到:
标签:Cassanda Data PoolingOptions Spring 启动 获取 设置
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定