我在使用Java异步驱动程序( 3.8.1 )时遇到一些麻烦。
我将描述我的环境:
我有一个副本集(rs0),其中包含3种距离:让我称它们为A,B,C。 在我的应用程序中,我使用Mongo和两个不同的Java驱动程序sync和async。
一开始我没有遇到任何问题,但是当主服务器崩溃(并在几分钟后更改其作为辅助服务器的行为后出现)时,我使用异步驱动程序的那部分代码无法使用事务和会话。
错误如下:
com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected
at com.mongodb.async.client.MongoClientImpl$1.onResult(MongoClientImpl.java:90)
at com.mongodb.async.client.MongoClientImpl$1.onResult(MongoClientImpl.java:83)
at com.mongodb.async.client.ClientSessionHelper$2.onResult(ClientSessionHelper.java:77)
at com.mongodb.async.client.ClientSessionHelper$2.onResult(ClientSessionHelper.java:73)
at com.mongodb.internal.connection.BaseCluster$ServerSelectionRequest.onResult(BaseCluster.java:433)
at com.mongodb.internal.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:309)
at com.mongodb.internal.connection.BaseCluster.access$800(BaseCluster.java:65)
at com.mongodb.internal.connection.BaseCluster$WaitQueueHandler.run(BaseCluster.java:482)
at java.lang.Thread.run(Unknown Source)
2019-01-21 17:02:01.906 ERROR 17560 --- [271de4498944329] org.mongodb.driver.client : Callback onResult call produced an error
java.lang.NullPointerException: null
at it.mypackage.mongo.service.ProcessoDocumentService$1.onResult(ProcessoDocumentService.java:124)
at it.mypackage.mongo.service.ProcessoDocumentService$1.onResult(ProcessoDocumentService.java:1)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.async.client.MongoClientImpl$1.onResult(MongoClientImpl.java:90)
at com.mongodb.async.client.MongoClientImpl$1.onResult(MongoClientImpl.java:83)
at com.mongodb.async.client.ClientSessionHelper$2.onResult(ClientSessionHelper.java:77)
at com.mongodb.async.client.ClientSessionHelper$2.onResult(ClientSessionHelper.java:73)
at com.mongodb.internal.connection.BaseCluster$ServerSelectionRequest.onResult(BaseCluster.java:433)
at com.mongodb.internal.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:309)
at com.mongodb.internal.connection.BaseCluster.access$800(BaseCluster.java:65)
at com.mongodb.internal.connection.BaseCluster$WaitQueueHandler.run(BaseCluster.java:482)
at java.lang.Thread.run(Unknown Source)
仅供参考,如果我在使用会话和事务时注释部分代码,则错误是经典超时,因为驱动程序不再能够找到副本集。
有人可以帮助我吗?我想念的是什么?
这是我创建MongoClient的方式:
connectionString = new ConnectionString("mongodb://address1:27017,address2:27018,address3:27019/?replicaSet=rs0");
MongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(connectionString)
.build();
settings = settings.builder().credential(credential).build();
asyncMongoClientInstance = MongoClients.create(settings);
答案 0 :(得分:0)
我自己找到了解决方案,就像聪明人曾经说过的:“如果您需要帮助,请在手臂的末端找到它。”
让我们专注于这部分代码:
Check dependencies
Code Signing Error: Signing for "Appname" requires a development team. Select a development team in the project editor.
Swift 3 mode has been deprecated and will be removed in a later version of Xcode. Please migrate "Appname" to Swift 4.2 using "Convert > To Current Swift Syntax…" in the Edit menu.
Swift 3 mode has been deprecated and will be removed in a later version of Xcode. Please migrate "Appname" to Swift 4.2 using "Convert > To Current Swift Syntax…" in the Edit menu.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 12.1'
我正在将设置对象重新分配给另一个没有连接字符串的对象。 因此,异步库不再知道在哪里处理连接。
为什么我要这么做?我想在名称上添加凭据到设置。但是这种方式是不可能的。因此,我创建了两个不同的设置对象,一个带有凭据,另一个没有。
chunked(size: Int)
现在肯定可以使用此对象。