我正在使用Astyanax 2.0.1连接到Cassandra。
我正在构建我的AstyanaxContext:
this.context = new AstyanaxContext.Builder()
.forCluster(config.getClusterName())
.forKeyspace(config.getKeyspace())
.withConnectionPoolConfiguration(connectionPoolConfiguration)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.TOKEN_AWARE)
)
.withConnectionPoolMonitor(new Slf4jConnectionPoolMonitorImpl())
.buildKeyspace(ThriftFamilyFactory.getInstance());
this.context.start();
在此之后,我尝试创建密钥空间(如果它尚不存在),我得到以下内容:
AddHost: test-cassandra
HostAdded: test-cassandra(192.168.2.111):9160
BadRequestException: [host=test-cassandra(192.168.2.111):9160, latency=8(24), attempts=1]InvalidRequestException(why:Keyspace 'test' does not exist)
哪个是正确的(然后我将继续创建密钥空间)。但是如果密钥空间确实存在,我得到:
AddHost: test-cassandra
HostAdded: test-cassandra(192.168.2.111):9160
AddHost: 127.0.0.1
HostAdded: 127.0.0.1(127.0.0.1):9160
RemoveHost: test-cassandra
HostRemoved: test-cassandra(192.168.2.111):9160
这会创建一个错误的上下文,因为它现在开始指向localhost并最终以
失败PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=2001(2001), attempts=1]Timed out waiting for connection
如果我配置错误,有什么想法吗?