I have seen example of cassandra driver where cluster name or keyspace name is specified without specifying the host ip address.
If i have multi node cluster how does the connection string work in cassandra.
In its simplest form, you configure the driver with the "contact points" which are the list of nodes it can contact to discover the topology of the cluster. These contact points are similar to the way the seeds list work for the gossip protocol.
There are several drivers that DataStax maintain:
Note that this isn't the complete list of drivers for Cassandra. There are drivers maintained by other Cassandra enthusiasts in the community.
Let's use the Java driver as an example since it is the most popular. Here is a simple bit of code that creates a session to the cluster:
CqlSession session = CqlSession.builder() .addContactPoint(new InetSocketAddress("10.1.2.3", 9042)) .withKeyspace("communityks") .withLocalDatacenter("DC1") .build();
Note the method .addContactPoint()
which identifies one of the nodes in the cluster as a contact point. Now that we've created a session object, we can execute queries against the database without needing to specify the contact points again. For example, we can insert data into a table with:
session.execute( SimpleStatement.builder( "INSERT INTO communityks.users (name, address) VALUES (?,?,?)") .addPositionalValues("tom", "100 Main Rd") .build());
If you're interested, we have a Katacoda scenario for the Java Driver where you can quickly learn the basics of writing a Java app that writes to and reads from a Cassandra database. Try it out for yourself now. It only takes about 10 minutes.
Once you complete the scenario, it would be great if you complete the questionnaire at the end to provide us feedback as we would love to hear from you. Cheers!
7 People are following this question.
What is the recommended way of dealing with the 1024-connection limit per node?
Do datastax Cassandra drivers send SNI headers with TLS requests?
Clarification on pagination internals
Cassandra TCP connections through PHP/Java
How can I restrict an app user to only connect to specific nodes in a cluster?
DataStax Enterprise is powered by the best distribution of Apache Cassandra ™
© 2023 DataStax, Titan, and TitanDB are registered trademarks of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.
Privacy Policy Terms of Use