AWS DocumentDB with spring boot fails Error : No server chosen by com.mongodb.client.internal.MongoClientDelegate

3.1k views Asked by At

My application is written in spring boot and working fine with a self-managed MongoDB server. Now I am trying to connect my same spring boot application with AWS DocumentDB. I started a documentDB cluster and connecting with spring-boot with the following configuration.

spring.data.mongodb.uri=mongodb://<user>:<password>@<my-cluster-endpoint>:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false
spring.data.mongodb.database=mydb

I have disabled TLS and it is showing TLS Enabled: No in cluster detail. I am deploying my spring boot application in an EC2 instance which is running in the same vpc as documentdb is running, I have cross checked it. When running my application I am getting the following error.

No server chosen by com.mongodb.client.internal.MongoClientDelegate$1@51a81d99 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message}, caused by {java.net.SocketTimeoutException: Read timed out}}]}. Waiting for 30000 ms before timing out

I am not finding a good source for working with documentdb in spring-boot. Any idea of how to find the exact reason?

1

There are 1 answers

1
Ashish On

You can try enabling the tls back but use -Djdk.tls.client.protocols=TLSv1.2 with the command line to downgrade the tls version.

Or try upgrading the Java version.