带有spring cassandra的微服务不能故障转移到远程集群

vom3gejh  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(322)

我设置了两个数据中心(dc1,dc2),每个中心有3个节点。一致性级别为本地\u仲裁,串行一致性级别为本地\u串行。本地数据中心是dc1。当本地数据中心中只有一个节点处于活动状态时,micro服务不会自动故障切换到dc2,而是不断抱怨“没有足够的副本可用于在一致性本地\u仲裁处进行查询(需要2个,但只有1个处于活动状态)”。任何建议都将不胜感激。
maven依赖项:

org.springframework.boot:spring-boot:jar:2.3.7.RELEASE
org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.3.7.RELEASE
org.springframework.data:spring-data-cassandra:jar:3.0.6.RELEASE
com.datastax.oss:java-driver-core:4.10.0

亚马尔:

spring:
  data:
    cassandra:
      consistency-level: local_quorum
      serial-consistency-level: LOCAL_SERIAL
      local-datacenter: DC1
      other configs: ...

代码:

public class CassandraConfig {

    @Bean
    public CqlSessionBuilderCustomizer sessionBuilderConfigurer() {
        return cqlSessionBuilder ->
                cqlSessionBuilder
                        .withAuthCredentials("username", "pwd");
    }

    @Bean
    public DriverConfigLoaderBuilderCustomizer driverConfigLoaderBuilderCustomizer() {
        return loaderBuilder -> loaderBuilder
                .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(10000))
                .withBoolean(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_ALLOW_FOR_LOCAL_CONSISTENCY_LEVELS, true)
                .withInt(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_MAX_NODES_PER_REMOTE_DC, 3);
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题