Package core :: Module event_bus :: Class EventBus

[hide private]
[frames] | no frames]

# Class EventBus

source code

    object --+
             |
            EventBus

This class represents a distributed lightweight event bus which can encompass multiple vert.x instances. It is very useful for otherwise isolated vert.x application instances to communicate with each other.

Messages sent over the event bus are JSON objects represented as Ruby Hash instances.

The event bus implements a distributed publish / subscribe network.

Messages are sent to an address.

There can be multiple handlers registered against that address. Any handlers with a matching name will receive the message irrespective of what vert.x application instance and what vert.x instance they are located in.

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 will 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.

When receiving a message in a handler the received object is an instance of EventBus::Message - this contains the actual Hash of the message plus a reply method which can be used to reply to it.

Static Methods | [hide private]

java_eventbus() | source code

send(address, message, reply_handler=None) Send a message on the event bus | source code

publish(address, message) Publish a message on the event bus | source code

send_or_pub(send, address, message, reply_handler=None) | source code

register_handler(address, local_only=False, handler=None) Register a handler. | source code

register_simple_handler(local_only=False, handler=None) Registers a handler against a uniquely generated address, the address is returned as the id received by the handler. | source code

unregister_handler(handler_id) Unregisters a handler | source code

convert_msg(message) | source code

Class Variables | [hide private]

| handler_dict = `{}`

Method Details | [hide private]

### send(address, message, reply_handler=None)
Static Method

source code

Send a message on the event bus

Keyword arguments:

Parameters:
  - `address` - the address to publish to
  - `message` - The message to send
  - `reply_handler` - An optional reply handler. It will be called when the reply from a receiver is received.

### publish(address, message)
Static Method

source code

Publish a message on the event bus

Keyword arguments:

Parameters:
  - `address` - the address to publish to
  - `message` - The message to publish

### register_handler(address, local_only=False, handler=None)
Static Method

source code

Register a handler.

Keyword arguments:

Parameters:
  - `address` - the address to register for. Any messages sent to that address will be received by the handler. A single handler can be registered against many addresses.
  - `local_only` - if True then handler won't be propagated across cluster
  - `handler` - The handler
Returns:
  id of the handler which can be used in EventBus.unregister_handler

### register_simple_handler(local_only=False, handler=None)
Static Method

source code

Registers a handler against a uniquely generated address, the address is returned as the id received by the handler. A single handler can be registered against many addresses.

Keyword arguments:

Parameters:
  - `local_only` - If Rrue then handler won't be propagated across cluster
  - `handler` - The handler
Returns:
  id of the handler which can be used in EventBus.unregister_handler

### unregister_handler(handler_id)
Static Method

source code

Unregisters a handler

Keyword arguments:

Parameters:
  - `handler_id` - the id of the handler to unregister. Returned from EventBus.register_handler