我从Lagom环境连接到AWS Managed Cassandra Service时遇到问题。这是我尝试过的结果,
(1)Amazon提供了有关从Java代码连接到AWS MCS的说明:
https://docs.aws.amazon.com/fr_fr/mcs/latest/devguide/cqlsh.html#using_java_driver
说明的要点是,您需要安装证书,然后将其传递给JVM,如下所示:
-Djavax.net.ssl.trustStore=path_to_file/cassandra_truststore.jks
-Djavax.net.ssl.trustStorePassword=amazon
然后,您可以使用任何您选择的Cassandra Java驱动程序。而我的选择是Lagom框架随附的DataStax驱动程序。
这是通过将以下内容添加到build.sbt
来完成的:
javaOptions ++= Seq(
"-Djavax.net.ssl.trustStore=project/cassandra_truststore.jks",
"-Djavax.net.ssl.trustStorePassword=amazon"
)
// Must enable JVM forking to use javaOptions with runAll.
fork := true
(2)在将Lagom应用程序部署到AWS之前,我想以Dev模式使用它,但是将其连接到AWS MCS而不是嵌入式Cassandra服务器。 Lagom提供了在开发模式下执行此操作的说明:
说明的要点是将以下行添加到build.sbt
:
lagomCassandraEnabled in ThisBuild := false
lagomUnmanagedServices in ThisBuild := Map("cas_native" -> "tcp://localhost:9042")
此示例中的URI假定在localhost:9042
上运行Cassandra服务器。就我而言,我用cassandra.us-east-1.amazonaws.com:9142
代替了。
(3)但是,当我运行sbt runAll
时,尝试访问AWS MCS时会超时:
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: cassandra.us-east-1.amazonaws.com/3.83.168.143:9142 (com.datastax.driver.core.exceptions.OperationTimedOutException: [cassandra.us-east-1.amazonaws.com/3.83.168.143:9142] Operation timed out))
(4)我通过完全绕过Lagom并仅编写一段非常简单的代码来隔离问题,如下所示:
System.setProperty("javax.net.ssl.trustStore", "redacted_absolute_file_path/cassandra_truststore.jks")
System.setProperty("javax.net.ssl.trustStorePassword", "amazon")
val cluster = Cluster.builder.addContactPoint("cassandra.us-east-1.amazonaws.com").withPort(9142).build()
val session = cluster.connect()
session.close()
cluster.close()
这很简单。但是会发生相同的超时。我在做什么错了?
答案 0 :(得分:0)
通过查看AWS MCS Python文档找到了一个解决方案(Java文档对此问题非常沉默)。事实证明,我确实需要配置MCS服务特定的凭据,然后按如下所示在Lagom的application.conf
文件中提供它们:
cassandra.default {
port = 9142
ssl.truststore {
path = "path/cassandra_truststore.jks"
password = "amazon"
}
authentication {
username = "service-specific username"
password = "service-specific password"
}
}
cassandra-journal {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}
cassandra-snapshot-store {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}
lagom.persistence.read-side.cassandra {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}