Using the EventBus without Verticles

113 views
Skip to first unread message

frances...@ignitetech.com

unread,
Aug 20, 2017, 4:13:08 AM8/20/17
to vert.x
Hi everyone,

Is there a difference in using the eventbus with or without a verticle? I mean, how many threads are used by the eventbus by default if used in an application with no Verticles? In which thread are the consumer handlers processed?

For example, are this two equivalent?
One:
class MyVerticle extends AbstractVerticle {
   
@Override
   
public void start() {
      vertx
.eventBus().consumer<String>("someAddress", ... )
   
}

}

Two:
class Not_A_Verticle {

   private final Vertx vertx;

   Not_A_Verticle(Vertx vertx) {
       this.vertx = vertx;
       start();
   }
  
   public void start() {
      vertx
.eventBus().consumer<String>("someAddress", ... )
   
}
}

Do they behave the same way at runtime?

I am a little confused about this point and I can't figure out an answer in the Vertx docs.

Regards

Jez P

unread,
Aug 20, 2017, 5:15:06 AM8/20/17
to vert.x
All handlers created in a verticle's start method will run on the same context, which in turn means that those handlers will only be accessed by a single thread.

This will not be the case in your second scenario - you cannot guarantee that all handlers you assign in the Not_A_Verticle class will be run on the same thread. Therefore if you share any state between those handlers, you will run into problems.

frances...@ignitetech.com

unread,
Aug 20, 2017, 5:45:14 AM8/20/17
to vert.x
Hi Jez,

based on your reply, can I state that if the handlers are stateless then there is no difference between the two code blocks?
BTW, I still don't understand what thread pool is used by the eventbus, is it always single threaded? Is it proportional to the number of cores? Can I manually set it?

Jez P

unread,
Aug 20, 2017, 6:17:17 AM8/20/17
to vert.x
I'd rather talk specifics than in the abstract. So could you explain why the answers to the questions are important to you, i.e. what's your use-case?

In answer to your question about the event bus IIRC the default number of event loop threads is 2 * number of cores, but I believe you can manually set it

Jez P

unread,
Aug 20, 2017, 6:19:54 AM8/20/17
to vert.x
And if your primary reason is curiosity, why not just do some experimenting with outputting thread names in your handlers?

frances...@ignitetech.com

unread,
Aug 22, 2017, 4:13:58 AM8/22/17
to vert.x
Hi Jez,

thanks for all the info. I don't have specific use-cases; I am studying enterprise architectures and vertx is an interesting example.
I saw that the eventbus has many backends, would it be feasible to build one based on Kafka? 

Julien Viet

unread,
Aug 22, 2017, 9:46:53 AM8/22/17
to ve...@googlegroups.com
the current clustered event bus (returned by vertx.eventBus()) uses its own transport mechanism (p2p TCP) and the “backend" is a cluster manager that shares the address map between the peers.

I don’t think Kafka would do that out of the box.

That being said, maybe a full clustered EventBus implementation could be done with Kafka ?

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/440d6e50-e2e1-4e7b-bf07-ed2338bc0da9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

frances...@ignitetech.com

unread,
Aug 23, 2017, 8:47:29 AM8/23/17
to vert.x
Hi Julien,

for a previous project I created an event bus based on Kafka; I would say that it was quite easy to achieve. Of course, this implies sending messages directly to kafka instead of your own p2p TCP mechanism. In addition, with kafka you do not keep track of the address map of the peers because this is done directly in the broker itself.

Julien Viet

unread,
Aug 23, 2017, 8:56:31 AM8/23/17
to ve...@googlegroups.com
thanks for your feedback, that’s interesting.

was also Kafka used for local delivery ?



frances...@ignitetech.com

unread,
Aug 23, 2017, 1:42:26 PM8/23/17
to vert.x

On Wednesday, August 23, 2017 at 2:56:31 PM UTC+2, Julien Viet wrote:
was also Kafka used for local delivery ?

The project was a big application implemented with a micro-services architecture (they were more "macro-services" I would say). The kafka based eventbus was the entry point of each module, this means that each module exposed its services and consumed external services always through the bus. As a consequence, the bus was not used for local delivery; this was not an explicit decision but just a consequence of the global design.
Each module was usually deployed as a standalone java application; btw, it was possible to package more of them together in the same executable jar; in this last case we could say that kafka was used for local delivery since the module lived in the same java application.

Among the others, one feature that I loved of the Kafka based eventbus was the fact that Kafka persists the message queue and if a consumer disconnects when it comes back, it can receive the messages from where it left.
Reply all
Reply to author
Forward
0 new messages