public interface EventBus extends Measured
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.
Modifier and Type | Field and Description |
---|---|
static java.util.function.Function<String,Boolean> |
DEFAULT_SERIALIZABLE_CHECKER
Default
Serializable class checker used by Vert.x when serializableChecker(Function) has not been set. |
Modifier and Type | Method and Description |
---|---|
<T> EventBus |
addInboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Add an interceptor that will be called whenever a message is received by Vert.x
|
<T> EventBus |
addOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Add an interceptor that will be called whenever a message is sent from Vert.x
|
EventBus |
clusterSerializableChecker(java.util.function.Function<String,Boolean> classNamePredicate)
Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded as
ClusterSerializable . |
EventBus |
codecSelector(java.util.function.Function<Object,String> selector)
Set selector to be invoked when the bus has not found any codec for a
Message body. |
<T> MessageConsumer<T> |
consumer(String address)
Create a message consumer against the specified address.
|
<T> MessageConsumer<T> |
consumer(String address,
Handler<Message<T>> handler)
Create a consumer and register it against the specified address.
|
<T> MessageConsumer<T> |
localConsumer(String address)
Like
consumer(String) but the address won't be propagated across the cluster. |
<T> MessageConsumer<T> |
localConsumer(String address,
Handler<Message<T>> handler)
Like
consumer(String, Handler) but the address won't be propagated across the cluster. |
EventBus |
publish(String address,
Object message)
Publish a message.
|
EventBus |
publish(String address,
Object message,
DeliveryOptions options)
Like
publish(String, Object) but specifying options that can be used to configure the delivery. |
<T> MessageProducer<T> |
publisher(String address)
Create a message publisher against the specified address.
|
<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. |
EventBus |
registerCodec(MessageCodec codec)
Register a message codec.
|
<T> EventBus |
registerDefaultCodec(Class<T> clazz,
MessageCodec<T,?> codec)
Register a default message codec.
|
<T> EventBus |
removeInboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Remove an interceptor that was added by
addInboundInterceptor(Handler) |
<T> EventBus |
removeOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Remove an interceptor that was added by
addOutboundInterceptor(Handler) |
default <T> Future<Message<T>> |
request(String address,
Object message)
Like
request(String, Object, Handler) but returns a Future of the asynchronous result |
<T> Future<Message<T>> |
request(String address,
Object message,
DeliveryOptions options)
Like
request(String, Object, DeliveryOptions, Handler) but returns a Future of the asynchronous result |
default <T> EventBus |
request(String address,
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. |
default <T> EventBus |
request(String address,
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. |
EventBus |
send(String address,
Object message)
Sends a message.
|
EventBus |
send(String address,
Object message,
DeliveryOptions options)
Like
send(String, Object) but specifying options that can be used to configure the delivery. |
<T> MessageProducer<T> |
sender(String address)
Create a message sender against the specified address.
|
<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. |
EventBus |
serializableChecker(java.util.function.Function<String,Boolean> classNamePredicate)
Register a predicate to invoke when verifying if an object is allowed to be encoded/decoded as
Serializable . |
EventBus |
unregisterCodec(String name)
Unregister a message codec.
|
EventBus |
unregisterDefaultCodec(Class clazz)
Unregister a default message codec.
|
isMetricsEnabled
static final java.util.function.Function<String,Boolean> DEFAULT_SERIALIZABLE_CHECKER
Serializable
class checker used by Vert.x when serializableChecker(Function)
has not been set.EventBus send(String address, Object message)
The message will be delivered to at most one of the handlers registered to the address.
address
- the address to send it tomessage
- the message, may be null
EventBus send(String address, Object message, DeliveryOptions options)
send(String, Object)
but specifying options
that can be used to configure the delivery.address
- the address to send it tomessage
- the message, may be null
options
- delivery optionsdefault <T> EventBus request(String address, Object message, Handler<AsyncResult<Message<T>>> replyHandler)
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.
address
- the address to send it tomessage
- the message body, may be null
replyHandler
- reply handler will be called when any reply from the recipient is receiveddefault <T> Future<Message<T>> request(String address, Object message)
request(String, Object, Handler)
but returns a Future
of the asynchronous resultdefault <T> EventBus request(String address, Object message, DeliveryOptions options, Handler<AsyncResult<Message<T>>> replyHandler)
request(String, Object, Handler)
but specifying options
that can be used to configure the delivery.address
- the address to send it tomessage
- the message body, may be null
options
- delivery optionsreplyHandler
- reply handler will be called when any reply from the recipient is received<T> Future<Message<T>> request(String address, Object message, DeliveryOptions options)
request(String, Object, DeliveryOptions, Handler)
but returns a Future
of the asynchronous resultEventBus publish(String address, Object message)
The message will be delivered to all handlers registered to the address.
address
- the address to publish it tomessage
- the message, may be null
EventBus publish(String address, Object message, DeliveryOptions options)
publish(String, Object)
but specifying options
that can be used to configure the delivery.address
- the address to publish it tomessage
- the message, may be null
options
- the delivery options<T> MessageConsumer<T> consumer(String address)
The returned consumer is not yet registered
at the address, registration will be effective when MessageConsumer.handler(io.vertx.core.Handler)
is called.
address
- the address that it will register it at<T> MessageConsumer<T> consumer(String address, Handler<Message<T>> handler)
address
- the address that will register it athandler
- the handler that will process the received messages<T> MessageConsumer<T> localConsumer(String address)
consumer(String)
but the address won't be propagated across the cluster.address
- the address to register it at<T> MessageConsumer<T> localConsumer(String address, Handler<Message<T>> handler)
consumer(String, Handler)
but the address won't be propagated across the cluster.address
- the address that will register it athandler
- the handler that will process the received messages<T> MessageProducer<T> sender(String address)
The returned sender will invoke the send(String, Object)
method when the stream WriteStream.write(Object)
method is called with the sender
address and the provided data.
address
- the address to send it to<T> MessageProducer<T> sender(String address, DeliveryOptions options)
sender(String)
but specifying delivery options that will be used for configuring the delivery of
the message.address
- the address to send it tooptions
- the delivery options<T> MessageProducer<T> publisher(String address)
The returned publisher will invoke the publish(String, Object)
method when the stream WriteStream.write(Object)
method is called with the publisher
address and the provided data.
address
- The address to publish it to<T> MessageProducer<T> publisher(String address, DeliveryOptions options)
publisher(String)
but specifying delivery options that will be used for configuring the delivery of
the message.address
- the address to publish it tooptions
- the delivery optionsEventBus registerCodec(MessageCodec 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.
codec
- the message codec to registerEventBus unregisterCodec(String name)
name
- the name of the codec<T> EventBus registerDefaultCodec(Class<T> clazz, MessageCodec<T,?> 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.
clazz
- the class for which to use this codeccodec
- the message codec to registerEventBus unregisterDefaultCodec(Class clazz)
clazz
- the class for which the codec was registeredEventBus codecSelector(java.util.function.Function<Object,String> selector)
Message
body.
The selector must return the name of a codec which has been registered with either registerCodec(MessageCodec)
or registerDefaultCodec(Class, MessageCodec)
.
selector
- the codec selector<T> EventBus addOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)
interceptor
- the interceptor<T> EventBus removeOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)
addOutboundInterceptor(Handler)
interceptor
- the interceptor<T> EventBus addInboundInterceptor(Handler<DeliveryContext<T>> interceptor)
interceptor
- the interceptor<T> EventBus removeInboundInterceptor(Handler<DeliveryContext<T>> interceptor)
addInboundInterceptor(Handler)
interceptor
- the interceptorEventBus clusterSerializableChecker(java.util.function.Function<String,Boolean> classNamePredicate)
ClusterSerializable
.
This is only used when Vert.x is clustered.
classNamePredicate
- the predicateEventBus serializableChecker(java.util.function.Function<String,Boolean> classNamePredicate)
Serializable
.
This is only used when Vert.x is clustered.
classNamePredicate
- the predicateCopyright © 2024 Eclipse. All rights reserved.