Alexander Nurmsalu
Alexander Nurmsalu

Reputation: 156

Vertx multithreaded worker verticle doesn't process messages in parallel

We use Vertx 3.0.0.

Situaton:

We have main verticle with REST handlers.

REST handler calls worker over event bus like this:

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:

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. 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. For instance, 2 Worker instances can handle 2 messages at the same time.

Upvotes: 4

Views: 3100

Answers (1)

Alexander Nurmsalu
Alexander Nurmsalu

Reputation: 156

OK, after short investigation with Vert.x team it appeared that this issues is fixed in yesterday's release v 3.1.0. Here is some discussion on this topic: https://groups.google.com/forum/#!msg/vertx/JEAJbGGQgeI/uTLDtaHBCAAJ

Upvotes: 3

Related Questions