Reputation: 24154
I have started working with Cassandra database recently and I am using Netflix client to populate and read the data from Cassandra database.
I have a single cluster with four nodes. I have created keyspace like this-
create keyspace profilekeyspace
with placement_strategy = 'NetworkTopologyStrategy'
and strategy_options = {DC2 : 1, DC1 : 1}
and durable_writes = true;
And my column family name is- profile_columnfamily
These are my four nodes-
lp-host01.vip.slc.qa.host.com:9160
lp-host02.vip.slc.qa.host.com:9160
lp-host03.vip.phx.qa.host.com:9160
lp-host04.vip.phx.qa.host.com:9160
Now currently I am using only one node from the above to make a connection to Cassandra database and populate the data. But my DBA's said, you need to use all the four nodes to make the connection.
private AstyanaxContext<Keyspace> context;
private CassandraAstyanaxConnection() {
context = new AstyanaxContext.Builder()
.forCluster("TEST CLUSTER")
.forKeyspace("PROFILE")
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setSeeds("lp-host01.vip.slc.qa.host.com:9160:9160")//using only node from above to make the connection
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2"))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getEntity();
emp_cf = ColumnFamily.newColumnFamily(
"PROFILE_COLUMNFAMILY",
StringSerializer.get(),
StringSerializer.get());
}
Now I am not sure how to use all the four nodes to make the connection using Netflix client? Can anyone help me with that?
Thanks for the help.
Upvotes: 0
Views: 684
Reputation: 11100
The seeds list is a comma separated list. So you can just add the rest in the setSeeds call:
setSeeds("server1:9160,server2:9160,server3:9160")
Also, Astyanax will discover the other servers in the ring. You only need to list one to discover all the others, but should that server be down you want to list more. It is very much like the seeds list in cassandra.yaml.
Note you have duplicated the port in your line:
.setSeeds("lp-host01.vip.slc.qa.host.com:9160:9160")
Upvotes: 2