从lagom连接到aws管理的cassandra服务

oyjwcjzk  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(473)

从lagom环境连接到aws管理的cassandra服务时遇到问题。以下是我尝试过的,有什么结果。
(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

然后,您可以使用任何您选择的cassandrajava驱动程序。我的选择是lagom框架提供的datasax驱动程序。
为此,我在 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模式下使用它,但将其连接到awsmcs,而不是嵌入式cassandra服务器。lagom提供了在开发模式下执行此操作的说明:
https://www.lagomframework.com/documentation/1.6.x/scala/cassandraserver.html#connecting-到本地运行的cassandra示例
说明的要点是在下面的行中添加 build.sbt :

lagomCassandraEnabled in ThisBuild := false
lagomUnmanagedServices in ThisBuild := Map("cas_native" -> "tcp://localhost:9042")

本例中的uri假设一个cassandra服务器在 localhost:9042 . 就我而言,我用 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()

这很简单。但同样的超时也会发生。我做错什么了?

t0ybt7op

t0ybt7op1#

通过查看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}
  }
}

相关问题