mongo java driver 3.4.3副本集连接可以监视成员

时间:2017-10-18 07:20:39

标签: java mongodb dns

使用:Ubuntu 16.04.3

我通过mongodb java驱动程序v3.4.3(或3.5.0)连接到副本集。我可以通过提供IP或我在/ etc / hosts文件中提供的主机名来创建MongoClient:

 new MongoClient( 
    Arrays.asList(
        new ServerAddress("X.X.Y.A",27017),
        new ServerAddress("X.X.Y.B",27017),
        new ServerAddress("X.X.Y.C",27017))
);

new MongoClient(new MongoClientURI("mongodb://X.X.Y.A:27017/?replicaSet=my-rs"));

//myserver1 on /etc/hosts  as X.X.Y.A    myserver1
new MongoClient(new MongoClientURI("mongodb://myserver1:27017/?replicaSet=my-rs")); 

在这两种情况下,mongodb都试图将副本集监视为" mongodb1" ," mongodb2"和" mongodb3"并继续抛出INFO日志并阻止执行:

Oct 18, 2017 9:12:13 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Exception in monitor thread while connecting to server mongodb3:27017
com.mongodb.MongoSocketException: mongodb1
    at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188)
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57)
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: mongodb1
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at java.net.InetAddress.getByName(InetAddress.java:1076)
    at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186)
    ... 5 more

抛出" mongodb2"的类似例外情况和" mongodb3"

但是当我在/ etc / hosts文件中添加mongodb1等行时,一切都工作为:

X.X.Y.A   mongodb1
X.X.Y.B   mongodb2
X.X.Y.C   mongodb3

这让我认为mongo驱动程序硬编码监控复制集的N个成员为" mongodbN:port"。这是mongodb java驱动程序上的一个错误,还是只是一种无用的方式呢?

0 个答案:

没有答案