Build Cloud-Native apps with Apache Cassandra

GOT QUESTIONS from the Workshop? You're in the right place! Post a question here and we'll get you answers.

Click here for Week 7 Materials and Homework.

Registrations still open!


question

Shalini Ramachandra avatar image
Shalini Ramachandra asked ·

How can we add contact points which are not resolvable to the Java driver?

Based on the best practice suggested in the Cassandra workshop series, it is enough to add one contact point, but it is better to add multiple. The #addContact javadoc suggests the same. So we use the #addContactPoints to provide multiple host names. But when one of the host names is unresolvable, this method throws an exception and our application startup completely fails. How can we give multiple contact points and still be able to connect to the cluster when one of the hosts is unresolvable / unavailable?

Note: We use the DataStax Java driver 3.x

java driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

What you are trying to do is a bad idea. It makes no sense to configure a contact point which the driver cannot reach or contact.

The code clearly states:

Note that all contact points must be resolvable; if any of them cannot be resolved, this method will fail.

I don't recommend making the driver connect to a hostname that doesn't exist. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you @Erick Ramirez. So does that mean that all hosts should definitely be "resolvable". But at least one of them should be "reachable"?

0 Likes 0 · ·

It is stated right there in the code link you provided in your question. Cheers!

1 Like 1 · ·