java - 无法使用 Hector 在 cassandra db 中插入值

标签 java cassandra hector

我正在使用 hector 在 cassandra 数据库中插入值。我使用 Eclipse helios IDE 和 Cassandra 1.1.2 版,在我的类路径中导入了以下 jar。

  • apache-cassandra-1.1.2.jar
  • hector-core-0.7.0.29.jar
  • libthrift-0.8.0.jar
  • slf4j-api-1.6.6.jar

我没有弄清楚这里有什么问题,无论是兼容性问题还是代码困惑。

我尝试使用不同版本的 jar ,但没有成功。 以下是代码片段。

请帮忙。

int count = 0;
StringSerializer ss = StringSerializer.get();
String cf = "TESTING";
CassandraHostConfigurator conf = new CassandraHostConfigurator("10.100.10.177:8160");
System.out.println("host configured..");

conf.setCassandraThriftSocketTimeout(40000);
conf.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_BLOCK);
conf.setRetryDownedHostsDelayInSeconds(5);
conf.setRetryDownedHostsQueueSize(128);
conf.setRetryDownedHosts(true);
conf.setLoadBalancingPolicy(new LeastActiveBalancingPolicy());
String key = Long.toString(System.currentTimeMillis());
Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", conf);
Keyspace keyspace = HFactory.createKeyspace("Testing", cluster);
Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get());

while (!"q".equals(new Scanner(System.in).next().toString())) {
    try {
        mutator.insert(key, cf, HFactory.createColumn("column_" + count, "v_" + count, ss, ss));
        mutator.execute();
        count++;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

这是我在没有循环的情况下插入单个值时遇到的异常。

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cassandra.thrift.Column.<init>(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;J)V
at me.prettyprint.cassandra.model.HColumnImpl.<init>(HColumnImpl.java:36)
at me.prettyprint.hector.api.factory.HFactory.createColumn(HFactory.java:477)
at me.prettyprint.hector.api.factory.HFactory.createStringColumn(HFactory.java:488)
at ExampleDaoV2.main(ExampleDaoV2.java:66)

最佳答案

尝试使用不同的 thrift jar 文件,而不是 libthrift。 让我知道这是否有效。

关于java - 无法使用 Hector 在 cassandra db 中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11840083/

相关文章:

java - GWT/Apache POI 下载 Servlet : Incorrect filename on download

java - 我应该将哪个版本的 Java 与 Cassandra 2.0 一起使用?

java - cassandra UTF8 或 LongType 中的 key 验证类类型?

cassandra - 集群系统上的Cassandra一致性问题

java - 如何在 Maven 中排除 hector 的 slf4j

java - 如何将时间戳转换回相同的 UUID 字符串

java - JTextArea 追加 for 循环的结果

java - reducer 数量对集群节点数量的依赖性

java - 根据多个字段在一组用户定义的对象中查找 LIS

cassandra - Cassandra中批量修改主键DELETE和INSERT的副作用