我正在尝试使用 Hector 的基本定义来创建 Cassandra 集群。这是我的代码(仅连接和架构部分)。
CassandraHostConfigurator chc = new CassandraHostConfigurator(
"localhost");
chc.setMaxActive(20);
chc.setCassandraThriftSocketTimeout(3000);
chc.setMaxWaitTimeWhenExhausted(4000);
Cluster cluster = HFactory.getOrCreateCluster("mycluster", chc);
System.out.println("cluster: " + cluster.getKnownPoolHosts(false));
try{
KeyspaceDefinition keyspaceDef = cluster.describeKeyspace("sensornetwork");
} catch (HectorException he){
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("sensornetwork",
"ColumnFamilyName",
ComparatorType.BYTESTYPE);
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("sensornetwork",
ThriftKsDef.DEF_STRATEGY_CLASS,
1,
Arrays.asList(cfDef));
cluster.addKeyspace(newKeyspace, true);
}
// If keyspace does not exist, the CFs don't exist either. => create them.
Keyspace keyspace = HFactory.createKeyspace("sensornetwork", cluster);
我基本上是通过遵循 Hector 自己网站上的文档来做到这一点的。
我得到的错误是这个:
Exception in thread "main" me.prettyprint.hector.api.exceptions.HectorException: All host pools marked down. Retry burden pushed out to client. at me.prettyprint.cassandra.connection.HConnectionManager.getClientFromLBPolicy(HConnectionManager.java:401) at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:232) at me.prettyprint.cassandra.service.ThriftCluster.addKeyspace(ThriftCluster.java:168) at com.mycompany.mavenpails2.SpeedLayer.CassandraPrepwork(SpeedLayer.java:62)
显然,我正在创建一个没有工作池连接的集群。我已经更改了端口并尝试了所有方法,但无法使其工作。有什么建议吗?
最佳答案
很可能“localhost”没有监听 thrift。可能会想要使用像 https://github.com/datastax/java-driver 这样的 cql 客户端反而。否则请确保您在 cassandra.yaml 中启用了 thrift
关于java - 用Java创建Hector集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31732417/