У меня странная проблема при попытке перебрать коллекцию. Я использую SpringBoot и Mon go Java Driver и могу подключиться и точно аутентифицироваться к MongoDB на docker -создать и аутентифицировать. Но когда эта часть кода выполняется, она выдает ошибку.
@Autowired
private MongoCollection<Document> collection;
@Scheduled(initialDelay = 112500,fixedRate = 3600000) //1 hour 3600000
public void sendEngagementNotification() {
Date timeNow = new Date();
FindIterable<Document> iterable = collection.find();
MongoCursor<Document> cursor = iterable.iterator();
try {
while (cursor.hasNext()) {
...
}
}
Это дает мне следующую трассировку стека:
mongo | 2020-03-30T18:01:18.044+0000 I NETWORK [listener] connection accepted from 192.168.240.20:56152 #2 (2 connections now open)
mongo | 2020-03-30T18:01:18.058+0000 I NETWORK [conn2] received client metadata from 192.168.240.20:56152 conn2: { driver: { name: "mongo-java-driver|sync", version: "3.12.2" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "4.19.76-linuxkit" }, platform: "Java/IcedTea/1.8.0_212-b04" }
mongo | 2020-03-30T18:01:18.062+0000 I SHARDING [conn2] Marking collection admin.system.users as collection version: <unsharded>
mongo | 2020-03-30T18:01:18.289+0000 I ACCESS [conn2] SASL SCRAM-SHA-1 authentication failed for user on notification from client 192.168.240.20:56152 ; AuthenticationFailed: SCRAM authentication failed, storedKey mismatch
mongo | 2020-03-30T18:01:18.445+0000 I NETWORK [conn2] end connection 192.168.240.20:56152 (1 connection now open)
notification | 2020-03-30 18:01:18.450 INFO 20 --- [ scheduling-1] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2}] to mongo-notification:27017 because there was a socket exception raised by this connection.
notification | 2020-03-30 18:01:18.456 ERROR 20 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task
notification |
notification | com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='user', source='notification', password=<hidden>, mechanismProperties=<hidden>}
notification | at com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:201) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator.access$300(SaslAuthenticator.java:40) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:78) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:47) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:207) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:47) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:156) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:129) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:50) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:398) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:115) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:101) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:92) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:126) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.operation.FindOperation$1.call(FindOperation.java:728) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.operation.FindOperation$1.call(FindOperation.java:725) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:463) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.operation.FindOperation.execute(FindOperation.java:725) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.operation.FindOperation.execute(FindOperation.java:89) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:196) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:143) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at notification_service.EngagementTask.sendEngagementNotification(EngagementTask.java:42) ~[classes!/:na]
notification | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
notification | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
notification | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
notification | at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
notification | at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
notification | at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
notification | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_212]
notification | at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_212]
notification | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_212]
notification | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_212]
notification | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_212]
notification | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_212]
notification | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
notification | Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server mongo-notification:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
notification | at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:303) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:259) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:162) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:40) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:67) ~[mongo-java-driver-3.12.2.jar!/:na]
notification | ... 34 common frames omitted
Любое предложение по другому способу получения всех документов из коллекции ?
Редактировать 1: Это может быть проблема с ssl !? Jar отлично работает с контейнером mongodb без включенного SSL. Может быть потому, что он сам подписан? В чем здесь проблема?
Редактировать 2: Также нормально, что итератор открывает соединение? Есть ли способ его настроить?