我在将Java异步驱动程序连接到Mongodb Atlas上托管的副本集时遇到了一个烦人的问题。
我正在使用以下代码通过Mongo DB Java Async API 3.8.2和3.9.1连接到服务器。
我可以使用同步驱动程序使用完全相同的连接字符串进行连接。
private static String str = "mongodb+srv://RWUser:****@foo-cluster-s813m.mongodb.net/?retryWrites=true&streamType=netty";
public static void main(String... args) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
MongoClient mongoClient = MongoClients.create(str);
MongoDatabase database = mongoClient.getDatabase("mydb");
database.createCollection("coll", (result, t) -> latch.countDown());
latch.await();
}
这是日志的视图:
INFO: Cluster created with settings {hosts=[foo-cluster-shard-00-00-s813m.mongodb.net:27017, foo-cluster-shard-00-01-s813m.mongodb.net:27017, foo-cluster-shard-00-02-s813m.mongodb.net:27017], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='foo-cluster-shard-0'}
janv. 18, 2019 11:31:37 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server foo-cluster-shard-00-00-s813m.mongodb.net:27017 to client view of cluster
janv. 18, 2019 11:31:37 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server foo-cluster-shard-00-01-s813m.mongodb.net:27017 to client view of cluster
janv. 18, 2019 11:31:37 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server foo-cluster-shard-00-02-s813m.mongodb.net:27017 to client view of cluster
janv. 18, 2019 11:31:37 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by com.mongodb.async.client.ClientSessionHelper$1@2794eab6 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=foo-cluster-shard-00-00-s813m.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=foo-cluster-shard-00-01-s813m.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=foo-cluster-shard-00-02-s813m.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
据我了解,已经建立了连接,发现了集群,但没有从客户端选择主集群。
是否需要设置其他属性?在网络方面呢? Netty流工厂用于处理SSL。