A distributed lightweight event bus which can encompass multiple vert.x instances. The event bus implements publish / subscribe, point to point messaging and request-response messaging.

Messages sent over the event bus are represented by instances of the Message class.

For publish / subscribe, messages can be published to an address using one of the publish methods. An address is a simple String instance.

Handlers are registered against an address. There can be multiple handlers registered against each address, and a particular handler can be registered against multiple addresses. The event bus will route a sent message to all handlers which are registered against that address.

For point to point messaging, messages can be sent to an address using one of the send methods. The messages will be delivered to a single handler, if one is registered on that address. If more than one handler is registered on the same address, Vert.x will choose one and deliver the message to that. Vert.x will aim to fairly distribute messages in a round-robin way, but does not guarantee strict round-robin under all circumstances.

All messages sent over the bus are transient. On event of failure of all or part of the event bus messages may be lost. Applications should be coded to cope with lost messages, e.g. by resending them, and making application services idempotent.

The order of messages received by any specific handler from a specific sender should match the order of messages sent from that sender.

When sending a message, a reply handler can be provided. If so, it will be called when the reply from the receiver has been received. Reply messages can also be replied to, etc, ad infinitum

Different event bus instances can be clustered together over a network, to give a single logical event bus.

Instances of EventBus are thread-safe.

If handlers are registered from an event loop, they will be executed using that same event loop. If they are registered from outside an event loop (i.e. when using Vert.x embedded) then Vert.x will assign an event loop to the handler and use it to deliver messages to that handler.

By: Julien Viet

no subtypes hierarchy

EventBus(EventBus delegate)
Inherited Attributes
Attributes inherited from: Object
hash, string
publishshared void publish(String address, Payload message)

Publish a message

  • address

    The address to send it to

  • message

    The message

registerHandlershared Registration registerHandler<M>(String address, Anything(Message<M>) onMessage)

Registers a handler against the specified address. The method returns a registration whose:

  • the completed promise is resolved when the register has been propagated to all nodes of the event bus
  • the cancel() method can be called to cancel the registration
  • address

    The address to register it at

  • onMessage

    The handler

sendshared Promise<Message<M>> send<M = Nothing>(String address, Payload message)

Send a message via the event bus. The returned promise allows to receive any reply message from the recipient.

  • address

    The address to send it to

  • message

    The message

Inherited Methods
Methods inherited from: Object