rem*_*oel 5 java asynchronous driver mongodb
我在连接到托管在 Mongodb Atlas 上的副本集的 java 异步驱动程序时遇到了一个烦人的问题。
我使用以下代码通过 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();
}
Run Code Online (Sandbox Code Playgroud)
这是日志的视图:
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
Run Code Online (Sandbox Code Playgroud)
据我所知,连接已经建立,集群发现但没有从客户端选择主要。
是否有任何额外的属性设置?也许在网络方面?Netty 流工厂用于处理 SSL。
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |