连接到使用Spring响应式数据自动配置的AWS Keyspaces

huangapple go评论56阅读模式
英文:

Connect to AWS keyspaces with Spring reactive data autoconfiguration

问题

我尝试使用 spring-boot-starter-data-cassandra-reactive 连接到我的 AWS Keyspaces,但出现以下错误:

在类路径资源 [com/pams/framework/windsoncore/configurations/CassandraConfiguration.class] 中定义的名为 'cassandraSession' 的 Bean 创建错误:调用初始化方法失败;嵌套异常是 com.datastax.oss.driver.api.core.AllNodesFailedException:无法到达任何联系点,请确保您提供了有效的地址(显示第一个节点,使用 getAllErrors() 获取更多信息):节点(endPoint=cassandra.us-east-2.amazonaws.com:9142,hostId=null,hashCode=33a6c4f3):[com.datastax.oss.driver.api.core.DriverTimeoutException:[s5|control|id: 0xe0ebe047,L:/10.0.0.128:54474 - R:cassandra.us-east-2.amazonaws.com/3.12.23.155:9142] 协议初始化请求,第1步(OPTIONS):在 500 毫秒后超时]

我尝试了他们的文档,可以工作,但我想使用 Spring 自动配置和响应式 Cassandra 存储库。我已经在 application.yml 中添加了所有的配置,并将 trustStore 信息作为 JVM 参数传递。但是我无法解决这些错误。我已经尝试过查找解决方法,但没有找到有效的解决方案。

如果有人能帮我解决这个问题,我将不胜感激。

我还尝试了以下内容:

@Configuration
@Slf4j
@EnableReactiveCassandraRepositories
public class CassandraConfiguration extends AbstractReactiveCassandraConfiguration {

  
  @Override
  protected String getContactPoints() {
    return "cassandra.us-east-2.amazonaws.com";
  }

  @Override
  protected int getPort() {
    return 9142;
  }

  @Override
  protected String getKeyspaceName() {
    return "windson";
  }

  @Override
  protected CqlSession getRequiredSession() {
    // TODO Auto-generated method stub
    DriverConfigLoader loader = DriverConfigLoader.fromClasspath("application.conf");

    return CqlSession.builder().withConfigLoader(loader).build();
  }
}
英文:

Im trying to connect to my aws keyspaces using spring-boot-starter-data-cassandra-reactive and I get the following error:

Error creating bean with name 'cassandraSession' defined in class path resource [com/pams/framework/windsoncore/configurations/CassandraConfiguration.class]: Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=cassandra.us-east-2.amazonaws.com:9142, hostId=null, hashCode=33a6c4f3): [com.datastax.oss.driver.api.core.DriverTimeoutException: [s5|control|id: 0xe0ebe047, L:/10.0.0.128:54474 - R:cassandra.us-east-2.amazonaws.com/3.12.23.155:9142] Protocol initialization request, step 1 (OPTIONS): timed out after 500 ms]

I tried their documentation, that works, but I wanted to used the spring auto configuration and reactive cassandra repos. I added all the configurations in application.yml and passed the trustStore information as JVM args. But I cannot get past these errors. I've tried looking around for this and have not found a working solution.

I would appreciate if someone can help me out here.

I have also tried the following:

@Configuration
@Slf4j
@EnableReactiveCassandraRepositories
public class CassandraConfiguration extends AbstractReactiveCassandraConfiguration {

  
  @Override
  protected String getContactPoints() {
    return "cassandra.us-east-2.amazonaws.com";
  }

  @Override
  protected int getPort() {
    return 9142;
  }

  @Override
  protected String getKeyspaceName() {
    return "windson";
  }

  @Override
  protected CqlSession getRequiredSession() {
    // TODO Auto-generated method stub
    DriverConfigLoader loader = DriverConfigLoader.fromClasspath("application.conf");

    return CqlSession.builder().withConfigLoader(loader).build();
  }
}

答案1

得分: 1

你需要在 application.conf 文件中增加连接超时时间:

datastax-java-driver {
  advanced.connection {
    connect-timeout = 5 seconds
    init-query-timeout = 5 seconds
  }
}

或者升级到 Java 驱动程序 4.9 版本,其中 init-query-timeout 已经从 500 毫秒增加到了 5 秒。

英文:

You need to increase connection timeout in the application.conf file to:

datastax-java-driver {
  advanced.connection {
    connect-timeout = 5 seconds
    init-query-timeout = 5 seconds
  }
}

or upgrade to Java driver 4.9 where the init-query-timeout is already increased from 500 milliseconds to 5 seconds.

huangapple
  • 本文由 发表于 2020年9月6日 10:35:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63760209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定