Vertx Failed Connection 问题未捕获 JDBCClient (.getConnection)



我无法处理在 vertx-jdbc-client - 3.3.9 上的 JDBCClient 中连接失败的情况,例如:没有要路由的主机、连接超时等。因为方法.getConnection((不返回failedFuture,即使在错误的主机名,用户名和密码上也不会调用failed。

仅当为连接提供的所有参数都有效时,该方法才会成功执行,否则代码块将卡住并且永远不会调用 SQLConnection。即使在我的情况下,使用 try catch 块包装代码也不会出错。

JDBCClient client = JDBCClient.createNonShared(Holder.getInstance().getVertx(), databaseConfig);
client.getConnection(connect -> {
if (connect.failed()){
client.close();
return;
}
/* Create connection on success */
SQLConnection connection = connect.result();
/* Execute Query */

相关:Vertx 连接超时未捕获 JDBCClient (.getConnection(

如果使用 C3P0 连接池,请尝试以下操作:

databaseConfig.put("acquire_retry_attempts", 1).put("break_after_acquire_failure", true);

否则,池会不断尝试建立连接。

最新更新