我有一个简单的基于 crud 的应用程序,其中Apache Cassandra用作默认数据库。我使用Spring Data Cassandra进行 Cassandra 连接。
现在,我正在尝试使用 Cassandra java 驱动程序很好地支持的AWS Keyspace 。我已按照此文档进行配置。
但是,每当我启动应用程序时,我总是会遇到以下异常。
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: cassandra.us-east-2.amazonaws.com/<ip>:9142 (com.datastax.driver.core.exceptions.OperationTimedOutException: [cassandra.us-east-2.amazonaws.com/<ip>:9142] Operation timed out))
我在 application.properties 中添加了以下道具:
spring.data.cassandra.contact-points=cassandra.us-east-2.amazonaws.com
spring.data.cassandra.port=9142
spring.data.cassandra.cluster-name=<name>
spring.data.cassandra.username=<username>
spring.data.cassandra.password=<password>
我还尝试通过添加道具来使用 application.conf:
datastax-java-driver {
basic.contact-points = [ "cassandra.us-east-2.amazonaws.com:9142"]
advanced.auth-provider{
class = PlainTextAuthProvider
username = "<username>"
password = "<password>"
}
basic.load-balancing-policy {
local-datacenter = "us-east-2"
}
advanced.ssl-engine-factory {
class = DefaultSslEngineFactory
truststore-path = "/home/centos/keyspaces/cassandra_truststore.jks"
truststore-password = "<password>"
}
}
但还是一样的结果。请注意,trustStore 配置也作为 jvm 参数添加:
javax.net.ssl.trustStore=/home/centos/keyspaces/cassandra_truststore.jks
javax.net.ssl.trustStorePassword=<password>
奇怪的是,我可以从同一台机器远程登录到这个 Keyspace 主机端口,甚至可以使用以下命令直接连接到该实例:
conda activate python2
export SSL_CERTFILE="/home/centos/keyspaces/sf-class2-root.crt"
cqlsh cassandra.us-east-2.amazonaws.com 9142 -u <username> -p <password> --ssl