4

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?

Afsar edrisy
  • 1,985
  • 12
  • 28
  • This does not seem like an issue with spring-boot itself. Are you using the correct security group settings? DocumentDB does need inbound connection enabled on the DB port. Refer to "Enable inbound connection for your cluster's security group." in https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-create.html. One way to rule this out would be to run command like "telnet 27017" and see if you get successful connection. – krg265 Oct 15 '20 at 20:30
  • Yes I am using correct security group and I am able to connect with mongo shell from same EC2 instance. – Afsar edrisy Oct 16 '20 at 04:28
  • did you find a solution for this problem that you can share here? – Frank Mar 05 '21 at 12:31

1 Answers1

0

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.

greybeard
  • 2,249
  • 8
  • 30
  • 66
Ashish
  • 41
  • 6