Multiple eventbus or a single eventbus

1,189 views
Skip to first unread message

Naveen

unread,
Apr 19, 2014, 3:32:18 AM4/19/14
to ve...@googlegroups.com
Can a single eventbus be used for communication between two or more verticles? Or is it that an eventbus should be created for a verticle for its communications?

Jordan Halterman

unread,
Apr 19, 2014, 10:31:30 AM4/19/14
to ve...@googlegroups.com
Each Vert.x instance has a single event bus instance. When Vert.x instances are clustered, event buses within different instances will automatically connect to and communicate with one another. The event bus exists in all verticles and works to communicate with all verticles from all verticles within the same cluster, so you'll never have to create an event bus. It is exactly what you should be using to communicate between all your verticles. Java, Python, Ruby, JS, whatever. They all communicate with each other over the same event bus. 

On Apr 19, 2014, at 12:32 AM, Naveen <navee...@gmail.com> wrote:

Can a single eventbus be used for communication between two or more verticles? Or is it that an eventbus should be created for a verticle for its communications?

--
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.
For more options, visit https://groups.google.com/d/optout.

Naveen

unread,
Apr 20, 2014, 1:46:26 AM4/20/14
to ve...@googlegroups.com
So if I have two verticles and I do " new vertx.EventBus("http://localhost:8080/eventbus") " in both, it will invoke the same instance of event bus?

On more question. I have seen couple of ways to instantiate an event bus, like
       var eventbus = require('vertx/event_bus');
       var eventbus = vertx.eventBus;
       var eventbus = new vertx.EventBus("http://localhost:8080/eventbus");
Are there any differences in these?

Thanks Jordan.

Jordan Halterman

unread,
Apr 20, 2014, 2:00:25 AM4/20/14
to ve...@googlegroups.com
There is only one instance of the event bus. I think you're confusing server- and client-side examples. The event bus you're referring to that is instantiated is client side Javascript. In the case of client side JS, the event bus that you instantiate is a wrapper around a SockJS client on the client side which communicates (using the address provided) with an event bus bridge on the server side. Essentially, the event bus bridge is a Vert.x provided helper that allows client code to send messages to addresses within a server side Vert.x cluster over web sockets. See the event bus bridge documentation for any language for a better explanation.

Within verticles you should only ever have to use the vertx.eventBus which is simply a wrapper around the single Java-based event bus for the current Vert.x instance. In Vert.x verticles you should never have to create an event bus instance. That is only the case in client side JS AFAIK. In fact, the core Java API doesn't provide any API for creating an event bus. It only exposes a single event bus that's available within each verticle through vertx.eventBus(). The only reason client side JS event buses need to be constructed is because a URL to the event bus bridge must be provided for communication. Does that make sense?

Naveen

unread,
Apr 21, 2014, 12:19:01 AM4/21/14
to ve...@googlegroups.com
Well, that explains it. Thanks a lot Jordan.
Reply all
Reply to author
Forward
0 new messages