5
votes

I have recently started using Vert.x for my new project and I really like how Event Bus eases out messaging using Vert.x.

In my project, I want to implement a standard Publish/Subscribe mechanism where I have multiple Subscribers/Consumers listening on a particular address. So from Vert.x documentation I pretty much understand how to configure an event bus, register consumers on event bus and publish messages.

Now what I am looking for is, making the consumers handle messages sequentially and not in parallel. To elaborate, I want all the consumers to receive message one after the other and not together. I am not sure if it would be called chaining because the order of the handlers is not important right now for me. However, parallel processing of the given message by different handlers/consumers is something which I want to avoid in some particular scenario.

Is it possible to do in Vert.x? Will appreciate some suggestions on this.

Thanks & Regards, Keya

2

2 Answers

2
votes

Can you elaborate more on what you are actually trying to achieve by processing the messages sequentially? Is this some more complicated business process where each consumer implements only part of this process? Or do I get it wrong?

Anyway, Vert.x does not provide a way how to "synchronize" or make processing of a certain message by multiple consumers sequential.

What you will probably need to do is to define multiple messages, where each of these relates to that certain part of your business process and only triggers the consumer responsible for that part.

1
votes

You can mark the Verticles that can't run in parallel as worker verticles, and specify a custom worker pool that has only one thread on it.

However, you may want to consider whether those Verticles should really be separate Veriticles, or whether they would be best modeled as "methods" all called one by one from a single Vericle.