Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.vertx.groovy.core.eventbus
[Groovy] Class EventBus

    java.lang.Object
      org.vertx.groovy.core.eventbus.EventBus

    class EventBus

A distributed lightweight event bus which can encompass multiple vert.x instances. The event bus implements both publish / subscribe network and point to point messaging.

Messages sent over the event bus are represented by instances of the Message class. Subclasses of Message exist for messages that represent all primitive types as well as `String`, Buffer, byte[] and JsonObject

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.

Authors:
  Tim Fox

Constructor Summary
`EventBus(JEventBus jEventBus)`

Method Summary
`protected static java.lang.Object` | `convertMessage(java.lang.Object message)`
`void` | `publish(java.lang.String address, java.lang.Object message)` Publish a message on the event bus.
`java.lang.String` | `registerHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)` Registers a handler against the specified address.
`java.lang.String` | `registerLocalHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)` Registers a local handler against the specified address.
`java.lang.String` | `registerSimpleHandler(java.lang.Object handler, groovy.lang.Closure resultHandler = null)` Registers a handler against a uniquely generated address, the address is returned as the id.
`void` | `send(java.lang.String address, java.lang.Object message, groovy.lang.Closure replyHandler = null)` Send a message on the event bus.
`void` | `unregisterHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)` Unregisters a handler given the address and the handler
`void` | `unregisterSimpleHandler(java.lang.String id, groovy.lang.Closure resultHandler = null)` Unregister a handler given the unique handler id
`protected static java.lang.Object` | `wrapHandler(java.lang.Object replyHandler)`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Constructor Detail

### EventBus

    EventBus(JEventBus jEventBus)

Method Detail

### convertMessage

    protected static java.lang.Object convertMessage(java.lang.Object message)

### publish

    void publish(java.lang.String address, java.lang.Object message)

  Publish a message on the event bus. Message can be a java.util.Map (Representing a JSON message), a String, boolean, byte, short, int, long, float, double or org.vertx.java.core.buffer.Buffer
  Parameters:
    `address` - The address to publish it to
    `message` - The message

### registerHandler

    java.lang.String registerHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)

  Registers a handler against the specified address. When a message arrives the handler will receive an instance of Message
  Parameters:
    `address` - The address to register it at
    `handler` - The handler
    `resultHandler` - Optional completion handler. If specified, then when the register has been propagated to all nodes of the event bus, the handler will be called.
  Returns:
    A unique handler id

### registerLocalHandler

    java.lang.String registerLocalHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)

  Registers a local handler against the specified address. The handler info won't be propagated across the cluster. When a message arrives the handler will receive an instance of Message
  Parameters:
    `address` - The address to register it at
    `handler` - The handler
  Returns:
    A unique handler id

### registerSimpleHandler

    java.lang.String registerSimpleHandler(java.lang.Object handler, groovy.lang.Closure resultHandler = null)

  Registers a handler against a uniquely generated address, the address is returned as the id. When a message arrives the handler will receive an instance of Message
  Parameters:
    handler
    `resultHandler` - Optional result handler. If specified, then when the register has been propagated to all nodes of the event bus, the handler will be called.
  Returns:
    A unique handler id which is the same as the address

### send

    void send(java.lang.String address, java.lang.Object message, groovy.lang.Closure replyHandler = null)

  Send a message on the event bus. Message can be a java.util.Map (Representing a JSON message), a String, boolean, byte, short, int, long, float, double or org.vertx.java.core.buffer.Buffer
  Parameters:
    `address` - The address to send it to
    `message` - The message
    `replyHandler` - Reply handler will be called when any reply from the recipient is received

### unregisterHandler

    void unregisterHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)

  Unregisters a handler given the address and the handler
  Parameters:
    `address` - The address the handler was registered to
    `handler` - The handler
    `resultHandler` - Optional completion handler. If specified, then when the unregister has been propagated to all nodes of the event bus, the handler will be called.

### unregisterSimpleHandler

    void unregisterSimpleHandler(java.lang.String id, groovy.lang.Closure resultHandler = null)

  Unregister a handler given the unique handler id
  Parameters:
    `id` - The handler id
    `resultHandler` - Optional completion handler. If specified, then when the unregister has been propagated to all nodes of the event bus, the handler will be called.

### wrapHandler

    protected static java.lang.Object wrapHandler(java.lang.Object replyHandler)

Groovy Documentation