|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.
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), java.lang.Object#wait(long, int), 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(JEventBus jEventBus)
Method Detail |
---|
protected static java.lang.Object convertMessage(java.lang.Object message)
void publish(java.lang.String address, java.lang.Object message)
address
- The address to publish it tomessage
- The message
java.lang.String registerHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)
address
- The address to register it athandler
- The handlerresultHandler
- Optional completion handler. If specified, then when the register has been
propagated to all nodes of the event bus, the handler will be called.
java.lang.String registerLocalHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)
address
- The address to register it athandler
- The handler
java.lang.String registerSimpleHandler(java.lang.Object handler, groovy.lang.Closure resultHandler = null)
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.
void send(java.lang.String address, java.lang.Object message, groovy.lang.Closure replyHandler = null)
address
- The address to send it tomessage
- The messagereplyHandler
- Reply handler will be called when any reply from the recipient is received
void unregisterHandler(java.lang.String address, groovy.lang.Closure handler, groovy.lang.Closure resultHandler = null)
address
- The address the handler was registered tohandler
- The handlerresultHandler
- Optional completion handler. If specified, then when the unregister has been
propagated to all nodes of the event bus, the handler will be called.
void unregisterSimpleHandler(java.lang.String id, groovy.lang.Closure resultHandler = null)
id
- The handler idresultHandler
- Optional completion handler. If specified, then when the unregister has been
propagated to all nodes of the event bus, the handler will be called.
protected static java.lang.Object wrapHandler(java.lang.Object replyHandler)
Groovy Documentation