2

我正在尝试将我的 java spring boot 应用程序连接到我的 AWS Keyspaces 密钥空间。我已关注亚马逊文档,了解如何使用适用于 Apache Cassandra 的 DataStax Java 驱动程序 ( https://docs.aws.amazon.com/keyspaces/latest/devguide/using_java_driver.html ) 设置和配置此连接。我还查看了以下内容:

  1. 不支持使用 Amazon Keyspaces 的分区程序(适用于 Apache Cassandra)
  2. 使用 Spring 反应式数据自动配置连接到 AWS 键空间
  3. https://docs.spring.io/spring-data/cassandra/docs/3.2.0/reference/html/#cassandra.connectors

这是我收到的错误:

org.springframework.beans.factory.BeanCreationException:在类路径资源 [com/envase/connect/config/CassandraSetup.class] 中定义名称为“cassandraSession”的 bean 创建错误:调用 init 方法失败;嵌套异常是 com.datastax.oss.driver.api.core.AllNodesFailedException:无法到达任何联系点,请确保您提供了有效地址(显示前 1 个节点,更多信息请使用 getAllErrors()):Node(endPoint= cassandra.us-east-2.amazonaws.com:9142, hostId=null, hashCode=3fcfeaa9): [com.datastax.oss.driver.api.core.DriverTimeoutException: [s5|control|id: 0x19776100, L:/ 192.168.1.105:53683 - R:cassandra.us-east-2.amazonaws.com/3.12.23.181:9142] 协议初始化请求,步骤 1(选项):5000 毫秒后超时] 在 org.springframework.beans.factory .support.AbstractAutowireCapableBeanFactory。

它还会一遍又一遍地打印以下警告,直到引发上述错误:

2021-04-27 15:04:48.106 WARN 17664 --- [s4-admin-0] cdodinternal.core.pool.ChannelPool:[s4|/3.12.23.155:9142] 打开新通道时出错(ConnectionInitException:[s4 |id: 0x0e9e0986, L:/192.168.1.105:53764 - R:3.12.23.155/3.12.23.155:9142] 协议初始化请求,步骤 1 (STARTUP {CQL_VERSION=3.0.0, DRIVER_NAME=DataStax Java driver for Apache Cassandra( R), DRIVER_VERSION=4.8.0, CLIENT_ID=f943143d-48b5-40ce-9d3c-f12123f3d687}): 发送请求失败 (javax.net.ssl.SSLHandshakeException: 没有找到匹配 IP 地址 3.12.23.155 的主题替代名称))

构建.gradle:

plugins {
    id 'org.springframework.boot' version '2.4.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.envase.connect'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation group: 'com.datastax.oss', name: 'java-driver-core', version: '4.8.0'
    implementation group: 'com.datastax.oss', name: 'java-driver-query-builder', version: '4.8.0'
    implementation group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: '4.8.0'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-cassandra-reactive', version: '2.4.5'

我还为 com.datastax.oss 依赖项尝试了 4.9.0 和 4.11.0 版本

应用程序.conf

datastax-java-driver {
     basic.contact-points = ["cassandra.us-east-2.amazonaws.com:9142"]
     advanced.auth-provider {
         class = PlainTextAuthProvider
         username = "******"
         password = "******"
     }
     basic.load-balancing-policy {
         local-datacenter = "us-east-2"
     }
     advanced.connection {
         timeout = 30 seconds
         connect-timeout = 30 seconds
         init-query-timeout = 30 seconds
      }

     advanced.metadata {
         schema.enabled = "false"
         token-map.enabled = "false"
     }

     advanced.ssl-engine-factory {
         class = DefaultSslEngineFactory
         cipher-suites = [ "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA" ]
         truststore-path = "./src/main/resources/cassandra_truststore.jks"
         truststore-password = "****"
     }
 }

cassandra 配置类:

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractReactiveCassandraConfiguration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;

@Configuration
@EnableReactiveCassandraRepositories
public class CassandraSetup extends AbstractReactiveCassandraConfiguration {


  @Value("${cassandra.contact-points}")
  private String contactPoints;

  @Value("${cassandra.port}")
  private int port;

  @Value("${cassandra.keyspace}")
  private String keyspace;

  @Value("${cassandra.data.local-datacenter}")
  private String dataCenter;

  @Override
  protected String getKeyspaceName() {
    return keyspace;
  }

  @Override
  protected String getContactPoints() {
    return contactPoints;
  }

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

  @Override
  public SchemaAction getSchemaAction() {
    return SchemaAction.NONE;
  }

    @Override
    protected CqlSession getRequiredSession() {
        DriverConfigLoader loader = DriverConfigLoader.fromClasspath("application.conf");
        return CqlSession.builder().withConfigLoader(loader).withLocalDatacenter(dataCenter).build();
    }
}

无论我尝试什么,我都会继续遇到同样的错误。任何和所有的帮助将不胜感激。

4

2 回答 2

0

来自 AWS Keyspaces 的错误消息会误导超时。真正的问题是驱动程序的 ssl-engine-factory 配置为默认值 - 无。请参阅:https ://docs.datastax.com/en/developer/java-driver/4.13/manual/core/ssl/

当使用 spring 配置AbstractReactiveCassandraConfiguration时,datastax 配置 标准行为被覆盖并且不起作用。

类中的方法(getSessionBuilderConfigurerWrapperAbstractSessionConfiguration扩展AbstractReactiveCassandraConfiguration)仅将驱动程序类型安全配置定义为 defaultOverrides(系统属性)和 defaultReference(“reference.conf”)。

因此,为了应用您的配置,您应该覆盖类中getDriverConfigurationResourceAbstractSessionConfiguration并将其返回为Resource.

于 2021-11-24T16:43:40.697 回答
0

该问题看起来与您使用的证书有关

这是线索:

"javax.net.ssl.SSLHandshakeException: No subject alternative names matching IP address 3.12.23.15"

看看这个: Java CertificateException“没有与 IP 地址匹配的主题替代名称......找到”

于 2021-04-27T20:29:32.010 回答