简体   繁体   English

Vertx多线程工作器Verticle不会并行处理消息

[英]Vertx multithreaded worker verticle doesn't process messages in parallel

We use Vertx 3.0.0. 我们使用Vertx 3.0.0。

Situaton: Situaton:

We have main verticle with REST handlers. 我们有REST处理程序的主要Verticle。

REST handler calls worker over event bus like this: REST处理程序通过事件总线调用worker,如下所示:

vertx.eventBus().send(
            "sample.data",
            "hello vert.x",
            r -> {
                System.out.println("[Main] Receiving reply ' " + r.result().body()
                        + "' in " + Thread.currentThread().getName());
            }
    );

We have worker verticle and this is how we execute this verticle: 我们有工作者Verticle,这就是我们执行这个verticle的方式:

vertx.deployVerticle("com.example.Worker",
                            new DeploymentOptions().setWorker(true).setMultiThreaded(true));

Here is Worker implementation: 这是工人实施:

public class Worker extends AbstractVerticle {


@Override
public void start() throws Exception {
    System.out.println("[Worker] Starting in " + Thread.currentThread().getName());

    vertx.eventBus().consumer("sample.data", message -> {
        System.out.println("[Worker] Consuming data in " + Thread.currentThread().getName());
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String body = (String) message.body();
        message.reply(body.toUpperCase());
    });

}
}

If I request my REST service multiple times then all messages are processed sequentially in our Worker. 如果我多次请求我的REST服务,那么所有消息将在我们的Worker中按顺序处理。 Why multithreading doesn't work here? 为什么多线程在这里不起作用? And what is the purpose of multithreading option of worker (it is unclear from docs how it works exactly)? 工作者的多线程选项的目的是什么(从文档中不清楚它是如何工作的)?

BTW, if I execute multiple instances of Worker using deployment options then I get parallel processing of my messages. 顺便说一句,如果我使用部署选项执行多个Worker实例,那么我会得到我的消息的并行处理。 For instance, 2 Worker instances can handle 2 messages at the same time. 例如,2个Worker实例可以同时处理2条消息。

OK, after short investigation with Vert.x team it appeared that this issues is fixed in yesterday's release v 3.1.0. 好的,经过对Vert.x团队的简短调查后,看来这个问题在昨天的发布v 3.1.0中得到修复。 Here is some discussion on this topic: https://groups.google.com/forum/#!msg/vertx/JEAJbGGQgeI/uTLDtaHBCAAJ 以下是对此主题的一些讨论: https//groups.google.com/forum/#! msg / vertx / JEAJbGGQgeI / uTLDtaHBCAAJ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM