Top Description Fields Methods
io.vertx.core.eventbus

public Interface EventBus

extends Measured
Known Direct Subinterfaces
io.vertx.core.eventbus.impl.EventBusInternal
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.Fluent, .GenIgnore, .Nullable, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.eventbus.impl.DefaultSerializableChecker, io.vertx.core.metrics.Measured, java.util.function.Function

A Vert.x event-bus is a light-weight distributed messaging system which allows different parts of your application, or different applications and services to communicate with each in a loosely coupled way.

An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.

Message delivery is best-effort and messages can be lost if failure of all or part of the event bus occurs.

Please refer to the documentation for more information on the event bus.

Author
Tim Fox

Field Summary

Modifier and TypeField and Description
public static final Function<String, Boolean>
DEFAULT_SERIALIZABLE_CHECKER

Default java.io.Serializable class checker used by Vert.x when serializableChecker(Function) has not been set.

Method Summary

Modifier and TypeMethod and Description
public <T> EventBus

Returns:

a reference to this, so the API can be used fluently
addInboundInterceptor
(Handler<DeliveryContext<T>>
the interceptor
interceptor
)

Add an interceptor that will be called whenever a message is received by Vert.x

public <T> EventBus

Returns:

a reference to this, so the API can be used fluently
addOutboundInterceptor
(Handler<DeliveryContext<T>>
the interceptor
interceptor
)

Add an interceptor that will be called whenever a message is sent from Vert.x

public EventBus

Returns:

a reference to this, so the API can be used fluently
clusterSerializableChecker
(Function<String, Boolean>
the predicate
classNamePredicate
)

Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded as io.vertx.core.shareddata.ClusterSerializable.

public EventBus

Returns:

a reference to this, so the API can be used fluently
codecSelector
(Function<Object, String>
the codec selector
selector
)

Set selector to be invoked when the bus has not found any codec for a Message body.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
consumer
(MessageConsumerOptions
the consumer options
options
)

Create a message consumer against the specified options address.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
consumer
(MessageConsumerOptions
the consumer options
options
,
Handler<Message<T>>
the handler that will process the received messages
handler
)

Create a consumer and register it against the specified options address.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
consumer
(String
the address that it will register it at
address
)

Create a message consumer against the specified address.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
consumer
(String
the address that will register it at
address
,
Handler<Message<T>>
the handler that will process the received messages
handler
)

Create a consumer and register it against the specified address.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
localConsumer
(String
the address to register it at
address
)

Like consumer(String) but the address won't be propagated across the cluster.

public <T> MessageConsumer<T>

Returns:

the event bus message consumer
localConsumer
(String
the address that will register it at
address
,
Handler<Message<T>>
the handler that will process the received messages
handler
)

Like consumer(String, Handler) but the address won't be propagated across the cluster.

public EventBus

Returns:

a reference to this, so the API can be used fluently
publish
(String
the address to publish it to
address
,
@Nullable Object
the message, may be null
message
)

Publish a message.

public EventBus

Returns:

a reference to this, so the API can be used fluently
publish
(String
the address to publish it to
address
,
@Nullable Object
the message, may be null
message
,
DeliveryOptions
the delivery options
options
)

Like publish(String, Object) but specifying options that can be used to configure the delivery.

public <T> MessageProducer<T>

Returns:

The publisher
publisher
(String
The address to publish it to
address
)

Create a message publisher against the specified address.

public <T> MessageProducer<T>

Returns:

The publisher
publisher
(String
the address to publish it to
address
,
DeliveryOptions
the delivery options
options
)

Like publisher(String) but specifying delivery options that will be used for configuring the delivery of the message.

public EventBus

Returns:

a reference to this, so the API can be used fluently
registerCodec
(MessageCodec<S, R>
the message codec to register
codec
)

Register a message codec.

public <T> EventBus

Returns:

a reference to this, so the API can be used fluently
registerDefaultCodec
(Class<T>
the class for which to use this codec
clazz
,
MessageCodec<T, ?>
the message codec to register
codec
)

Register a default message codec.

public <T> EventBus

Returns:

a reference to this, so the API can be used fluently
removeInboundInterceptor
(Handler<DeliveryContext<T>>
the interceptor
interceptor
)

Remove an interceptor that was added by addInboundInterceptor(Handler)

public <T> EventBus

Returns:

a reference to this, so the API can be used fluently
removeOutboundInterceptor
(Handler<DeliveryContext<T>>
the interceptor
interceptor
)

Remove an interceptor that was added by addOutboundInterceptor(Handler)

public default <T> EventBus

Returns:

a reference to this, so the API can be used fluently
request
(String
the address to send it to
address
,
@Nullable Object
the message body, may be null
message
,
Handler<AsyncResult<Message<T>>>
reply handler will be called when any reply from the recipient is received
replyHandler
)

Sends a message and specify a replyHandler that will be called if the recipient subsequently replies to the message.

public default <T> Future<Message<T>>
request(String address, @Nullable Object message)

Like request(String, Object, Handler) but returns a Future of the asynchronous result

public default <T> EventBus

Returns:

a reference to this, so the API can be used fluently
request
(String
the address to send it to
address
,
@Nullable Object
the message body, may be null
message
,
DeliveryOptions
delivery options
options
,
Handler<AsyncResult<Message<T>>>
reply handler will be called when any reply from the recipient is received
replyHandler
)

Like request(String, Object, Handler) but specifying options that can be used to configure the delivery.

public <T> Future<Message<T>>
request(String address, @Nullable Object message, DeliveryOptions options)

Like request(String, Object, DeliveryOptions, Handler) but returns a Future of the asynchronous result

public EventBus

Returns:

a reference to this, so the API can be used fluently
send
(String
the address to send it to
address
,
@Nullable Object
the message, may be null
message
)

Sends a message.

public EventBus

Returns:

a reference to this, so the API can be used fluently
send
(String
the address to send it to
address
,
@Nullable Object
the message, may be null
message
,
DeliveryOptions
delivery options
options
)

Like send(String, Object) but specifying options that can be used to configure the delivery.

public <T> MessageProducer<T>

Returns:

The sender
sender
(String
the address to send it to
address
)

Create a message sender against the specified address.

public <T> MessageProducer<T>

Returns:

The sender
sender
(String
the address to send it to
address
,
DeliveryOptions
the delivery options
options
)

Like sender(String) but specifying delivery options that will be used for configuring the delivery of the message.

public EventBus

Returns:

a reference to this, so the API can be used fluently
serializableChecker
(Function<String, Boolean>
the predicate
classNamePredicate
)

Register a predicate to invoke when verifying if an object is allowed to be encoded/decoded as java.io.Serializable.

public EventBus

Returns:

a reference to this, so the API can be used fluently
unregisterCodec
(String
the name of the codec
name
)

Unregister a message codec.

public EventBus

Returns:

a reference to this, so the API can be used fluently
unregisterDefaultCodec
(Class<T>
the class for which the codec was registered
clazz
)

Unregister a default message codec.

Inherited from io.vertx.core.metrics.Measured:
isMetricsEnabled

Field Detail

DEFAULT_SERIALIZABLE_CHECKERback to summary
public static final Function<String, Boolean> DEFAULT_SERIALIZABLE_CHECKER

Default java.io.Serializable class checker used by Vert.x when serializableChecker(Function) has not been set.

Annotations
@GenIgnore

Method Detail

addInboundInterceptorback to summary
public <T> EventBus addInboundInterceptor(Handler<DeliveryContext<T>> interceptor)

Add an interceptor that will be called whenever a message is received by Vert.x

Parameters
interceptor:Handler<DeliveryContext<T>>

the interceptor

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
addOutboundInterceptorback to summary
public <T> EventBus addOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)

Add an interceptor that will be called whenever a message is sent from Vert.x

Parameters
interceptor:Handler<DeliveryContext<T>>

the interceptor

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
clusterSerializableCheckerback to summary
public EventBus clusterSerializableChecker(Function<String, Boolean> classNamePredicate)

Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded as io.vertx.core.shareddata.ClusterSerializable.

This is only used when Vert.x is clustered.

Parameters
classNamePredicate:Function<String, Boolean>

the predicate

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
codecSelectorback to summary
public EventBus codecSelector(Function<Object, String> selector)

Set selector to be invoked when the bus has not found any codec for a Message body.

The selector must return the name of a codec which has been registered with either registerCodec(MessageCodec) or registerDefaultCodec(Class, MessageCodec).

Parameters
selector:Function<Object, String>

the codec selector

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
consumerback to summary
public <T> MessageConsumer<T> consumer(MessageConsumerOptions options)

Create a message consumer against the specified options address.

The returned consumer is not yet registered at the address, registration will be effective when MessageConsumer#handler(io.vertx.core.Handler) is called.

Parameters
options:MessageConsumerOptions

the consumer options

Returns:MessageConsumer<T>

the event bus message consumer

consumerback to summary
public <T> MessageConsumer<T> consumer(MessageConsumerOptions options, Handler<Message<T>> handler)

Create a consumer and register it against the specified options address.

Parameters
options:MessageConsumerOptions

the consumer options

handler:Handler<Message<T>>

the handler that will process the received messages

Returns:MessageConsumer<T>

the event bus message consumer

consumerback to summary
public <T> MessageConsumer<T> consumer(String address)

Create a message consumer against the specified address.

The returned consumer is not yet registered at the address, registration will be effective when MessageConsumer#handler(io.vertx.core.Handler) is called.

Parameters
address:String

the address that it will register it at

Returns:MessageConsumer<T>

the event bus message consumer

consumerback to summary
public <T> MessageConsumer<T> consumer(String address, Handler<Message<T>> handler)

Create a consumer and register it against the specified address.

Parameters
address:String

the address that will register it at

handler:Handler<Message<T>>

the handler that will process the received messages

Returns:MessageConsumer<T>

the event bus message consumer

localConsumerback to summary
public <T> MessageConsumer<T> localConsumer(String address)

Like consumer(String) but the address won't be propagated across the cluster.

Parameters
address:String

the address to register it at

Returns:MessageConsumer<T>

the event bus message consumer

localConsumerback to summary
public <T> MessageConsumer<T> localConsumer(String address, Handler<Message<T>> handler)

Like consumer(String, Handler) but the address won't be propagated across the cluster.

Parameters
address:String

the address that will register it at

handler:Handler<Message<T>>

the handler that will process the received messages

Returns:MessageConsumer<T>

the event bus message consumer

publishback to summary
public EventBus publish(String address, @Nullable Object message)

Publish a message.

The message will be delivered to all handlers registered to the address.

Parameters
address:String

the address to publish it to

message:@Nullable Object

the message, may be null

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
publishback to summary
public EventBus publish(String address, @Nullable Object message, DeliveryOptions options)

Like publish(String, Object) but specifying options that can be used to configure the delivery.

Parameters
address:String

the address to publish it to

message:@Nullable Object

the message, may be null

options:DeliveryOptions

the delivery options

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
publisherback to summary
public <T> MessageProducer<T> publisher(String address)

Create a message publisher against the specified address.

The returned publisher will invoke the publish(String, Object) method when the stream io.vertx.core.streams.WriteStream#write(Object) method is called with the publisher address and the provided data.

Parameters
address:String

The address to publish it to

Returns:MessageProducer<T>

The publisher

publisherback to summary
public <T> MessageProducer<T> publisher(String address, DeliveryOptions options)

Like publisher(String) but specifying delivery options that will be used for configuring the delivery of the message.

Parameters
address:String

the address to publish it to

options:DeliveryOptions

the delivery options

Returns:MessageProducer<T>

The publisher

registerCodecback to summary
public EventBus registerCodec(MessageCodec<S, R> codec)

Register a message codec.

You can register a message codec if you want to send any non standard message across the event bus. E.g. you might want to send POJOs directly across the event bus.

To use a message codec for a send, you should specify it in the delivery options.

Parameters
codec:MessageCodec<S, R>

the message codec to register

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
@GenIgnore:permitted-type
registerDefaultCodecback to summary
public <T> EventBus registerDefaultCodec(Class<T> clazz, MessageCodec<T, ?> codec)

Register a default message codec.

You can register a message codec if you want to send any non standard message across the event bus. E.g. you might want to send POJOs directly across the event bus.

Default message codecs will be used to serialise any messages of the specified type on the event bus without the codec having to be specified in the delivery options.

Parameters
clazz:Class<T>

the class for which to use this codec

codec:MessageCodec<T, ?>

the message codec to register

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
@GenIgnore
removeInboundInterceptorback to summary
public <T> EventBus removeInboundInterceptor(Handler<DeliveryContext<T>> interceptor)

Remove an interceptor that was added by addInboundInterceptor(Handler)

Parameters
interceptor:Handler<DeliveryContext<T>>

the interceptor

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
removeOutboundInterceptorback to summary
public <T> EventBus removeOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)

Remove an interceptor that was added by addOutboundInterceptor(Handler)

Parameters
interceptor:Handler<DeliveryContext<T>>

the interceptor

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
requestback to summary
public default <T> EventBus request(String address, @Nullable Object message, Handler<AsyncResult<Message<T>>> replyHandler)

Sends a message and specify a replyHandler that will be called if the recipient subsequently replies to the message.

The message will be delivered to at most one of the handlers registered to the address.

Parameters
address:String

the address to send it to

message:@Nullable Object

the message body, may be null

replyHandler:Handler<AsyncResult<Message<T>>>

reply handler will be called when any reply from the recipient is received

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
requestback to summary
public default <T> Future<Message<T>> request(String address, @Nullable Object message)

Like request(String, Object, Handler) but returns a Future of the asynchronous result

requestback to summary
public default <T> EventBus request(String address, @Nullable Object message, DeliveryOptions options, Handler<AsyncResult<Message<T>>> replyHandler)

Like request(String, Object, Handler) but specifying options that can be used to configure the delivery.

Parameters
address:String

the address to send it to

message:@Nullable Object

the message body, may be null

options:DeliveryOptions

delivery options

replyHandler:Handler<AsyncResult<Message<T>>>

reply handler will be called when any reply from the recipient is received

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
requestback to summary
public <T> Future<Message<T>> request(String address, @Nullable Object message, DeliveryOptions options)

Like request(String, Object, DeliveryOptions, Handler) but returns a Future of the asynchronous result

sendback to summary
public EventBus send(String address, @Nullable Object message)

Sends a message.

The message will be delivered to at most one of the handlers registered to the address.

Parameters
address:String

the address to send it to

message:@Nullable Object

the message, may be null

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendback to summary
public EventBus send(String address, @Nullable Object message, DeliveryOptions options)

Like send(String, Object) but specifying options that can be used to configure the delivery.

Parameters
address:String

the address to send it to

message:@Nullable Object

the message, may be null

options:DeliveryOptions

delivery options

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
senderback to summary
public <T> MessageProducer<T> sender(String address)

Create a message sender against the specified address.

The returned sender will invoke the send(String, Object) method when the stream io.vertx.core.streams.WriteStream#write(Object) method is called with the sender address and the provided data.

Parameters
address:String

the address to send it to

Returns:MessageProducer<T>

The sender

senderback to summary
public <T> MessageProducer<T> sender(String address, DeliveryOptions options)

Like sender(String) but specifying delivery options that will be used for configuring the delivery of the message.

Parameters
address:String

the address to send it to

options:DeliveryOptions

the delivery options

Returns:MessageProducer<T>

The sender

serializableCheckerback to summary
public EventBus serializableChecker(Function<String, Boolean> classNamePredicate)

Register a predicate to invoke when verifying if an object is allowed to be encoded/decoded as java.io.Serializable.

This is only used when Vert.x is clustered.

Parameters
classNamePredicate:Function<String, Boolean>

the predicate

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
unregisterCodecback to summary
public EventBus unregisterCodec(String name)

Unregister a message codec.

Parameters
name:String

the name of the codec

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
@GenIgnore:permitted-type
unregisterDefaultCodecback to summary
public EventBus unregisterDefaultCodec(Class<T> clazz)

Unregister a default message codec.

Parameters
clazz:Class<T>

the class for which the codec was registered

Returns:EventBus

a reference to this, so the API can be used fluently

Annotations
@Fluent
@GenIgnore