簡單的hector連線casssandra測試

oxoxooxx發表於2011-07-14

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部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1052468/,如需轉載,請註明出處,否則將追究法律責任。

相關文章