Exception opening socket (No server chosen by...from cluster description)

Hi ,

I am trying to connect (Java spring boot) to an Azure Cosmo DB for Mongo and getting the following error for remote part; but for the same code, I am able to connect to the local mongodb.

Local:
mongodb://localhost:27017

Remote:
mongodb://:@:10255/?ssl=true?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@username@

I have been researching and googling and trying different options but still cannot figure out.
Any suggestions or advice would be very much appreciated.a

Thank you.


2024-05-01 18:54:29.143  INFO 306023 --- [  restartedMain] org.mongodb.driver.cluster               : No server chosen by com.mongodb.client.internal.MongoClientDelegate$1@8716901 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=XYZ.mongo.cosmos.azure.com:10255, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
2024-05-01 18:54:39.090  INFO 306023 --- [azure.com:10255] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server XYZ.mongo.cosmos.azure.com:10255

com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.6.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:180) ~[mongodb-driver-core-4.6.1.jar:na]
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:193) ~[mongodb-driver-core-4.6.1.jar:na]
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:157) ~[mongodb-driver-core-4.6.1.jar:na]
        at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
Caused by: java.net.SocketTimeoutException: connect timed out
        at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
        at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412) ~[na:na]
        at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255) ~[na:na]
        at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237) ~[na:na]
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:na]
        at java.base/java.net.Socket.connect(Socket.java:609) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:305) ~[na:na]
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107) ~[mongodb-driver-core-4.6.1.jar:na]
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-4.6.1.jar:na]
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.6.1.jar:na]
        ... 4 common frames omitted