我正在尝试创建一个具有多个节点的远程集群,并在scala中使用特定的键空间打开会话。
我的sbt:
name := "CassandraConnect"
version := "0.1"
scalaVersion := "2.13.2"
libraryDependencies ++= {
Seq(
"com.datastax.cassandra" % "cassandra-driver-core" % "3.1.1",
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.9",
"org.slf4j" % "slf4j-api" % "1.7.5",
"org.scala-lang" % "scala-library" % "2.13.2"
)
}
我的代码:
val cluster: Cluster = Cluster.builder()
.addContactPoints(
"10.10.9.120",
"10.10.9.234",
"10.10.9.198")
.build()
var session = cluster.connect("test1")
我的控制台显示它已经打开了连接:
DEBUG com.datastax.driver.core.Host.STATES - [/10.10.9.120:9042] Connection[/10.10.9.120:9042-1, inFlight=0, closed=false] Transport initialized, connection ready
但是,当使用session作为“session.connect(keyspace)”时,它通过:
Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.10.9.120:9042 (com.datastax.driver.core.exceptions.OperationTimedOutException: [/10.10.9.120:9042] Operation timed out), /10.10.9.233:9042 (com.datastax.driver.core.exceptions.OperationTimedOutException: [/10.10.9.233:9042] Operation timed out), /10.10.9.121:9042 (com.datastax.driver.core.exceptions.OperationTimedOutException: [/10.10.9.121:9042] Operation timed out), /10.10.8.198:9042, /10.10.9.119:9042, /10.10.8.204:9042, /10.10.9.234:9042 [only showing errors of first 3 hosts, use getErrors() for more details])
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:233)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1455)
at com.datastax.driver.core.Cluster.init(Cluster.java:164)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:335)
at com.datastax.driver.core.Cluster.connect(Cluster.java:285)
at CassandraConnector$.delayedEndpoint$CassandraConnector$1(CassandraConnector.scala:15)
at CassandraConnector$delayedInit$body.apply(CassandraConnector.scala:3)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:73)
暂无答案!
目前还没有任何答案,快来回答吧!