Apache Beam-即使程序连续执行,也会捕获并引发异常。如何停止该过程或在管道中处理

时间:2018-11-09 09:33:38

标签: java mongodb apache-beam apache-beam-io

我有一个管道,该管道可获取数据mysql并用于将数据传输到mongo db 使用下面的代码运行此管道后,从mysql提取数据但无法加载到mongodb

noSqlresult.apply(MongoDbIO.write().withUri(mongoUri)
                .withDatabase(mongoDatabase)
                .withCollection(resultCollectionName));

我发现了以下异常和一些日志,这些日志不断尝试与mongo db通信

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='mongoUser', source='db1', password=<hidden>, mechanismProperties={}}
at com.mongodb.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:162)
at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:39)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:68)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:46)
at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:168)
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:46)
at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:122)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:52)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server severip:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
    at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
    at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295)
    at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)
    at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)
    at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:119)
    at com.mongodb.connection.SaslAuthenticator.access$000(SaslAuthenticator.java:39)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:52)
    ... 9 more
18/11/09 12:49:29 DEBUG org.mongodb.driver.cluster: Updating cluster description to  {type=UNKNOWN, servers=[{address=severip:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='mongoUser', source='db1', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server severip:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]
18/11/09 12:49:29 DEBUG org.mongodb.driver.connection: Closing connection connectionId{localValue:17}
18/11/09 12:49:29 DEBUG org.mongodb.driver.cluster: Updating cluster description to  {type=UNKNOWN, servers=[{address=severip:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='mongoUser', source='db1', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server severip:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]
18/11/09 12:49:29 DEBUG org.mongodb.driver.connection: Closing connection connectionId{localValue:18}

如何处理这种情况(如果不存在),mongo可以创建数据库,但是不能使用mongo客户端连接内部创建mongoIO。是否有可能处理

显示此错误的原因是由于注意力不集中,但现有数据库未获取异常,仅获取新数据库 究竟是什么原因以及如何处理这些错误

1 个答案:

答案 0 :(得分:0)

没有对象存储ptransform的结果,因此需要等待连接超时异常,此后,如果声明其他连接自动关闭,则可以执行在catch块中声明的操作。

如果您是处理异常的新手,我想您将从以下链接中得到答案

java_exception_handler_StackOverFlow