且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MongoClient for VertX中正确处理异常

更新时间:2022-11-19 08:13:14

当前不会引发异常,我认为这是设计上的错误,因为您收到了无法使用的对象.随时打开错误: https://github.com/vert-x3/vertx-mongo-client/issues

Currently the exception is not thrown, which in my opinion a mistake in design, since you receive an object that you cannot work with. Feel free to open a bug: https://github.com/vert-x3/vertx-mongo-client/issues

您可以检测20个重试尝试来检测客户端是死机还是到达":

What you can do to detect that your client is "dead or arrival" is to wait for 20 retry attempts:

MongoClient client = MongoClient.createShared(vertx, config, "pool_name");
client.findOne("some_collection", json1, json2, (h) -> {
    if (h.succeeded()) {
        //...
    }
    else {
        // Notify that the client is dead
    }
});