【问题标题】:Vertx Failed Connection issue not catched JDBCClient (.getConnection)Vertx 连接失败问题未捕获 JDBCClient (.getConnection)
【发布时间】:2020-07-03 13:08:22
【问题描述】:

我无法处理 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 connection timeout not catched JDBCClient (.getConnection)

【问题讨论】:

    标签: mysql jdbc vert.x


    【解决方案1】:

    如果你使用 C3P0 连接池,试试这个:

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

    否则池会一直尝试建立连接。

    【讨论】:

    • 看起来以下选项在 vertx-jdbc-client - 3.3.x 中不可用目前无法升级 vertx-jdbc-client 版本。提到了 c3p0.properties 添加附加参数。我将尝试实现这些,如果您以前在 vertx 中将其用作配置,我们将不胜感激。
    猜你喜欢
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 2014-09-18
    • 2016-04-26
    • 2020-08-15
    相关资源
    最近更新 更多