Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 流畅地使用Vertx mongodb客户端与内联客户端与嵌套客户端_Java_Mongodb_Vert.x - Fatal编程技术网

Java 流畅地使用Vertx mongodb客户端与内联客户端与嵌套客户端

Java 流畅地使用Vertx mongodb客户端与内联客户端与嵌套客户端,java,mongodb,vert.x,Java,Mongodb,Vert.x,通读这些文档,我仍然对以流畅的方式使用mongoClient的好处(如果有的话)感到困惑。有谁能向我解释一下,这是否能保证秩序 在线运行-两者将同时运行,不保证订单。 mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {}); mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {}); mongoClient.runCommand("a

通读这些文档,我仍然对以流畅的方式使用mongoClient的好处(如果有的话)感到困惑。有谁能向我解释一下,这是否能保证秩序

在线运行-两者将同时运行,不保证订单。

mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {});
mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {});
mongoClient.runCommand("aggregate", getSomeCommand1(), res1 -> {
       mongoClient.runCommand("aggregate", getSomeCommand2(), res2 -> {});
});
运行嵌套-getSomeCommand1将在getSomeCommand2之前首先运行完成。

mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {});
mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {});
mongoClient.runCommand("aggregate", getSomeCommand1(), res1 -> {
       mongoClient.runCommand("aggregate", getSomeCommand2(), res2 -> {});
});
流畅地跑步-与排队跑步相同吗?

mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {}).mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {});

远不是一个完整的答案,但运行一些基本的测试表明,以流畅的方式运行与在线运行是一样的

我在一个大数据集上运行了一个慢速命令(聚合)和一个快速命令(计数)

mongoClient.runCommand("aggregate", getTotalRecsPerTypeCommand(sellerId, collection), res -> {
    result.put("totalRecsPerType", res.result());
}).count(collection, new JsonObject().put("sellerId", sellerId), res -> {
    result.put("totalRecs", res.result());
    requestMessage.reply(result);
});
最初只返回总数,但是当应答从fast命令移到slow命令时,两个结果都会返回。这表明它们在没有订单保证的情况下同时运行

    mongoClient.runCommand("aggregate", getTotalRecsPerTypeCommand(sellerId, collection), res -> {
        result.put("totalRecsPerType", res.result());
        requestMessage.reply(result);
    }).count(collection, new JsonObject().put("sellerId", sellerId), res -> {
        result.put("totalRecs", res.result());
    });

按行运行不会保证执行顺序,也就是说,在负载不重的机器上多次运行第一个代码可能会保持顺序

fluent API也是如此。在这种情况下,省略分号只会有帮助。如果要创建一个流,在第一个命令结束后将触发下一个命令,请使用RxJava(或嵌套的情况,但从长远来看,最终可能会触发)

请看这里: 虽然我不太喜欢本课程中使用的
observefuture
(我建议使用),但这是一个很好的起点