Create a Cassandra keyspace with 'network topology' using Hector?

331 views Asked by At

I want to create a Cassandra keyspace with 'network topology'. I can do it using CLI like this.

CREATE KEYSPACE test
WITH placement_strategy = 'NetworkTopologyStrategy'
AND strategy_options={us-east:6,us-west:3};

How can I achieve the same using Hector?

Thanks,
Bhathiya

2

There are 2 answers

0
Bee On BEST ANSWER

For the record, this works.

Map<String,String> options = new HashMap<String,String>();
options.put("dc1", "3");    
options.put("dc2", "1");    
ThriftKsDef kd = (ThriftKsDef) HFactory.createKeyspaceDefinition(keyspaceName,
     strategyClass, replicationFactor, cfDefs);    
if(options != null){    
     kd.setStrategyOptions(options);    
}    
getCluster().addKeyspace(kd, true);
1
Lyuben Todorov On

You shouldn't do that. Back when Hector was the primary choice for a client driver, the recommendations were that you create your keyspace via the cassandra-CLI

Having said that, I would suggest that you use an up-to-date driver and recomend the DataStax binary protocol driver.