ITPub博客

首页 > 应用开发 > IT综合 > 简单的hector连接casssandra测试

简单的hector连接casssandra测试

原创 IT综合 作者:oxoxooxx 时间:2011-07-14 23:48:12 0 删除 编辑

import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;

public class ExampleClient {

public static void main(String[] args) throws IllegalStateException,Exception {
CassandraHostConfigurator cassandraHostConfigurator=new CassandraHostConfigurator("192.168.100.108:9160,192.168.100.110:9160");
cassandraHostConfigurator.setMaxActive(20);
cassandraHostConfigurator.setMaxIdle(5);
cassandraHostConfigurator.setCassandraThriftSocketTimeout(3000);
cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(4000);

StringSerializer stringSerializer=new StringSerializer();
Cluster cluster=HFactory.createCluster("cluster_name", cassandraHostConfigurator);

Keyspace ks=HFactory.createKeyspace("OBS", cluster);
String columnFamily = "bucket";
Mutator mutator =HFactory.createMutator(ks, stringSerializer);

mutator.insert("bucket_key", columnFamily, HFactory.createStringColumn("object_name", "object_value"));
System.out.println("testHetor");
cluster.getConnectionManager().shutdown();
}
}

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23937368/viewspace-1052468/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    178
  • 访问量
    843645