简体   繁体   English

从 Lagom 连接到 AWS Managed Cassandra 服务

[英]Connecting to AWS Managed Cassandra Service from Lagom

I'm having problems connecting to AWS Managed Cassandra Service from my Lagom environment.我在从 Lagom 环境连接到 AWS Managed Cassandra Service 时遇到问题。 Here's what I have tried, with what results.这是我尝试过的,结果如何。

(1) Amazon provides instructions for connecting to AWS MCS from Java code: (1) Amazon 提供了从 Java 代码连接到 AWS MCS 的说明:

https://docs.aws.amazon.com/fr_fr/mcs/latest/devguide/cqlsh.html#using_java_driver https://docs.aws.amazon.com/fr_fr/mcs/latest/devguide/cqlsh.html#using_java_driver

The gist of the instructions is that you need to install a certificate and then pass it to the JVM as follows:说明的要点是您需要安装证书,然后将其传递给 JVM,如下所示:

-Djavax.net.ssl.trustStore=path_to_file/cassandra_truststore.jks 
-Djavax.net.ssl.trustStorePassword=amazon

Then, you can use any Cassandra Java drivers of your choice.然后,您可以使用您选择的任何 Cassandra Java 驱动程序。 And my choice is the DataStax drivers provided with the Lagom framework.我选择的是 Lagom 框架提供的 DataStax 驱动程序。

This I did by adding the following to build.sbt :我通过将以下内容添加到build.sbtbuild.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) Before deploying my Lagom application to AWS, I want to work with it in Dev mode but connecting it to AWS MCS instead of the embedded Cassandra server. (2) 在将我的 Lagom 应用程序部署到 AWS 之前,我想在开发模式下使用它,但将它连接到 AWS MCS 而不是嵌入式 Cassandra 服务器。 Lagom provides instructions for doing this in Dev mode: Lagom 提供了在开发模式下执行此操作的说明:

https://www.lagomframework.com/documentation/1.6.x/scala/CassandraServer.html#Connecting-to-a-locally-running-Cassandra-instance https://www.lagomframework.com/documentation/1.6.x/scala/Cas​​sandraServer.html#Connecting-to-a-locally-running-Cassandra-instance

The gist of the instructions is to add the following lines to build.sbt :说明的要点是将以下几行添加到build.sbt

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

The URI in this example assumes a Cassandra server running on localhost:9042 .此示例中的 URI 假定 Cassandra 服务器在localhost:9042上运行。 In my case, I substituted that with cassandra.us-east-1.amazonaws.com:9142 .就我而言,我将其替换为cassandra.us-east-1.amazonaws.com:9142

(3) Nevertheless, when I run sbt runAll , I'm getting timeouts when trying to reach AWS MCS: (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) I have isolated the problem by bypassing Lagom entirely and just writing a very simple piece of code, like this: (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()

This is as simple as it gets.这很简单。 But the same timeout occurs.但发生同样的超时。 What am I doing wrong?我究竟做错了什么?

Found a solution by looking at the AWS MCS Python documentation (the Java documentation is conspicuously silent on the matter).通过查看 AWS MCS Python 文档找到了一个解决方案(Java 文档对此事明显保持沉默)。 Turns out I do need to configure MCS service-specific credentials and then provide them in the Lagom's application.conf file as follows:结果我确实需要配置 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}
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM