2

我正在尝试在 Windows 环境下将 Cassandra 与 Java 连接起来。以下是应用程序/OS/lib 版本。

-Windows 7
-Java 7
-Cassandra 2.1.12

代码:

Cluster clst;
Session ses;
clst= Cluster.builder().addContactPoint("127.0.0.1").withPort(9042).build();

Cassandra 和 nodetool 正在运行。下面是nodetool的状态。

C:\Program Files\DataStax Community\apache-cassandra\bin>nodetool -h localhost status
Starting NodeTool
Datacenter: datacenter1
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens  Owns    Host ID                               Rack
UN  127.0.0.1  245.99 KB  256     ?       61c6b0e5-2f83-4bc9-9b86-6507e2f06dfc  rack1

Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
C:\Program Files\DataStax Community\apache-cassandra\bin>

当我尝试将 cassandra 与 localhost/127.0.01 连接时,我在堆栈跟踪中遇到错误。

19:19:05.996 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing node list and token map
19:19:06.465 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] error on /127.0.0.1 connection (com.datastax.driver.core.TransportException: [/127.0.0.1] Unexpected exception triggered), no more host to try
19:19:06.469 [main] DEBUG com.datastax.driver.core.Cluster - Shutting down
Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: [/127.0.0.1])
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:162)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:83)
    at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:516)
    at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:473)
    at com.datastax.driver.core.Cluster.<init>(Cluster.java:65)
    at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:93)
    at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:458)
    at cass.Cass.main(Cass.java:16)
Java Result: 1

此外,我还尝试在其他站点上找到有关 stackoverflow 的解决方案,但未能解决我的问题。

有人对此查询有一些解决方案吗?

4

3 回答 3

0

从您的堆栈跟踪中,我怀疑您使用的是非常旧的 Java 驱动程序版本,可能是 1.x 系列(1.0.1?)的某个版本。尝试使用最新的 3.0.0 版本,看看错误是否仍然存在。

于 2016-02-09T09:56:35.437 回答
0

我发现了问题,我正在使用许多第三方库运行项目中的代码,其中一个导致错误(我还不知道是哪一个)。我替换了整个jar文件并解决了问题。转到以下 url 并根据您使用的 cassandra 版本下载 Java 驱动程序 jar 文件。 http://docs.datastax.com/en/developer/driver-matrix/doc/javaDrivers.html#java-drivers

于 2017-05-24T06:30:42.537 回答
0

请检查您的 rpc_address。我建议把 rpc_address= 0.0.0.0 和 broadcast_rpc_address= 监听地址可以是空白或机器 IP

于 2016-02-08T03:30:14.487 回答