I am currently doing some light development and incorporating a MongoDB instance into my application. I was able to connect to my local Mongo instance without much trouble, but I wanted to offload the MongoDB to an IBM cloud instance. I created the service, was able to connect to it with a client like MongoDB compass, and got through the TLS/cert config of the java driver.

My config looks like this:

data: 
  mongodb: 
     uri: mongodb://<username>:<password>@<randomclouduri>.databases.appdomain.cloud:30339,<randomclouduri2>.databases.appdomain.cloud:30339/ibmclouddb?authSource=admin&replicaSet=replset&ssl=true

A localhost URI comes across fine, but when connecting to the cloud replicaset, the java drive picks up a reference to "svc.cluster.local" and I get an error.

2019-05-05 09:47:34.322  INFO 21700 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-05-05 09:47:34.447  INFO 21700 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 108ms. Found 2 repository interfaces.
2019-05-05 09:47:38.467  INFO 21700 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (https)
2019-05-05 09:47:38.514  INFO 21700 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-05 09:47:38.515  INFO 21700 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-05-05 09:47:38.720  INFO 21700 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-05 09:47:38.720  INFO 21700 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 6535 ms
2019-05-05 09:47:42.663  INFO 21700 --- [  restartedMain] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[<randomclouduri>.databases.appdomain.cloud:30339, <randomclouduri2>.databases.appdomain.cloud:30339], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='replset'}
2019-05-05 09:47:42.664  INFO 21700 --- [  restartedMain] org.mongodb.driver.cluster               : Adding discovered server <randomclouduri>.databases.appdomain.cloud:30339 to client view of cluster
2019-05-05 09:47:42.723  INFO 21700 --- [  restartedMain] org.mongodb.driver.cluster               : Adding discovered server <randomclouduri2>.databases.appdomain.cloud:30339 to client view of cluster
2019-05-05 09:47:43.818  INFO 21700 --- [  restartedMain] c.e.s.m.service.MpsReplicationService    : Is production:false
2019-05-05 09:47:43.818  INFO 21700 --- [  restartedMain] c.e.s.m.service.MpsReplicationService    : Is performance:false
2019-05-05 09:47:43.890  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:52048}] to <randomclouduri2>.databases.appdomain.cloud:30339
2019-05-05 09:47:43.895  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:49594}] to <randomclouduri>.databases.appdomain.cloud:30339
2019-05-05 09:47:44.029  INFO 21700 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2019-05-05 09:47:44.037  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=<randomclouduri2>.databases.appdomain.cloud:30339, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0, 6]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=144219100, setName='replset', canonicalAddress=<randomclouduri2>.databases.appdomain.cloud:30339, hosts=[<randomclouduri2>.databases.appdomain.cloud:30339, <randomclouduri>.databases.appdomain.cloud:30339], passives=[], arbiters=[c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local:30339], primary='<randomclouduri2>.databases.appdomain.cloud:30339', tagSet=TagSet{[]}, electionId=7fffffff0000000000000002, setVersion=3, lastWriteDate=Sun May 05 09:47:34 ADT 2019, lastUpdateTimeNanos=346830642375200}
2019-05-05 09:47:44.041  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Adding discovered server c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local:30339 to client view of cluster
2019-05-05 09:47:44.042  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=<randomclouduri>.databases.appdomain.cloud:30339, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0, 6]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=145646800, setName='replset', canonicalAddress=<randomclouduri>.databases.appdomain.cloud:30339, hosts=[<randomclouduri2>.databases.appdomain.cloud:30339, <randomclouduri>.databases.appdomain.cloud:30339], passives=[], arbiters=[c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local:30339], primary='<randomclouduri2>.databases.appdomain.cloud:30339', tagSet=TagSet{[]}, electionId=null, setVersion=3, lastWriteDate=Sun May 05 09:47:34 ADT 2019, lastUpdateTimeNanos=346830647621900}
2019-05-05 09:47:44.042  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Setting max election id to 7fffffff0000000000000002 from replica set primary <randomclouduri2>.databases.appdomain.cloud:30339
2019-05-05 09:47:44.043  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Setting max set version to 3 from replica set primary <randomclouduri2>.databases.appdomain.cloud:30339
2019-05-05 09:47:44.043  INFO 21700 --- [ain.cloud:30339] org.mongodb.driver.cluster               : Discovered replica set primary <randomclouduri2>.databases.appdomain.cloud:30339
2019-05-05 09:47:44.150  INFO 21700 --- [ter.local:30339] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local:30339

com.mongodb.MongoSocketException: c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local
    at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188) ~[mongo-java-driver-3.8.2.jar:na]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongo-java-driver-3.8.2.jar:na]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:62) ~[mongo-java-driver-3.8.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126) ~[mongo-java-driver-3.8.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongo-java-driver-3.8.2.jar:na]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_201]
Caused by: java.net.UnknownHostException: c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a-0.c-18e01cd5-e0d7-452f-b3f7-db162d7db912-a.ed7ca1194fa444c7a256b8f91865944b.svc.cluster.local
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_201]
    at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source) ~[na:1.8.0_201]
    at java.net.InetAddress.getAddressesFromNameService(Unknown Source) ~[na:1.8.0_201]
    at java.net.InetAddress.getAllByName0(Unknown Source) ~[na:1.8.0_201]
    at java.net.InetAddress.getAllByName(Unknown Source) ~[na:1.8.0_201]
    at java.net.InetAddress.getAllByName(Unknown Source) ~[na:1.8.0_201]
    at java.net.InetAddress.getByName(Unknown Source) ~[na:1.8.0_201]
    at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186) ~[mongo-java-driver-3.8.2.jar:na]
    ... 5 common frames omitted

Why is my client driver discovering what I assume is an internal address to the mongodb instances within however IBM auto configs its instances? Is there a way around this, or am I down the wrong path myself?

0 Answers