Class EventBus
- java.lang.Object
-
- io.vertx.reactivex.core.eventbus.EventBus
-
- All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate,Measured
public class EventBus extends Object implements io.vertx.lang.rx.RxDelegate, Measured
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.
NOTE: This class has been automatically generated from the
originalnon RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static io.vertx.lang.rx.TypeArg<EventBus>__TYPE_ARG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> EventBusaddInboundInterceptor(Handler<DeliveryContext<T>> interceptor)Add an interceptor that will be called whenever a message is received by Vert.x<T> EventBusaddOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)Add an interceptor that will be called whenever a message is sent from Vert.xEventBusclusterSerializableChecker(Function<String,Boolean> classNamePredicate)Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded asClusterSerializable.EventBuscodecSelector(Function<Object,String> selector)Set selector to be invoked when the bus has not found any codec for aMessagebody.<T> MessageConsumer<T>consumer(MessageConsumerOptions options)Create a message consumer against the specified options address.<T> MessageConsumer<T>consumer(MessageConsumerOptions options, Handler<Message<T>> handler)Create a consumer and register it against the specified options address.<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.booleanequals(Object o)EventBusgetDelegate()inthashCode()booleanisMetricsEnabled()Whether the metrics are enabled for this measured object<T> MessageConsumer<T>localConsumer(String address)Likeconsumer(io.vertx.core.eventbus.MessageConsumerOptions)but the address won't be propagated across the cluster.<T> MessageConsumer<T>localConsumer(String address, Handler<Message<T>> handler)Likeconsumer(io.vertx.core.eventbus.MessageConsumerOptions)but the address won't be propagated across the cluster.static EventBusnewInstance(EventBus arg)EventBuspublish(String address, Object message)Publish a message.EventBuspublish(String address, Object message, DeliveryOptions options)Likepublish(java.lang.String, java.lang.Object)but specifyingoptionsthat 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)Likepublisher(java.lang.String)but specifying delivery options that will be used for configuring the delivery of the message.EventBusregisterCodec(MessageCodec codec)Register a message codec.<T> EventBusremoveInboundInterceptor(Handler<DeliveryContext<T>> interceptor)Remove an interceptor that was added byaddInboundInterceptor(io.vertx.core.Handler<io.vertx.reactivex.core.eventbus.DeliveryContext<T>>)<T> EventBusremoveOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)Remove an interceptor that was added byaddOutboundInterceptor(io.vertx.core.Handler<io.vertx.reactivex.core.eventbus.DeliveryContext<T>>)<T> Future<Message<T>>request(String address, Object message)Sends a message and specify areplyHandlerthat will be called if the recipient subsequently replies to the message.<T> Future<Message<T>>request(String address, Object message, DeliveryOptions options)Likerequest(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.<T> Single<Message<T>>rxRequest(String address, Object message)Sends a message and specify areplyHandlerthat will be called if the recipient subsequently replies to the message.<T> Single<Message<T>>rxRequest(String address, Object message, DeliveryOptions options)Likerequest(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.EventBussend(String address, Object message)Sends a message.EventBussend(String address, Object message, DeliveryOptions options)Likesend(java.lang.String, java.lang.Object)but specifyingoptionsthat 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)Likesender(java.lang.String)but specifying delivery options that will be used for configuring the delivery of the message.EventBusserializableChecker(Function<String,Boolean> classNamePredicate)Register a predicate to invoke when verifying if an object is allowed to be encoded/decoded asSerializable.StringtoString()EventBusunregisterCodec(String name)Unregister a message codec.
-
-
-
Field Detail
-
__TYPE_ARG
public static final io.vertx.lang.rx.TypeArg<EventBus> __TYPE_ARG
-
-
Method Detail
-
getDelegate
public EventBus getDelegate()
- Specified by:
getDelegatein interfaceMeasured- Specified by:
getDelegatein interfaceio.vertx.lang.rx.RxDelegate
-
isMetricsEnabled
public boolean isMetricsEnabled()
Whether the metrics are enabled for this measured object- Specified by:
isMetricsEnabledin interfaceMeasured- Returns:
trueif metrics are enabled
-
send
public EventBus send(String address, Object message)
Sends a message.The message will be delivered to at most one of the handlers registered to the address.
- Parameters:
address- the address to send it tomessage- the message, may benull- Returns:
- a reference to this, so the API can be used fluently
-
send
public EventBus send(String address, Object message, DeliveryOptions options)
Likesend(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.- Parameters:
address- the address to send it tomessage- the message, may benulloptions- delivery options- Returns:
- a reference to this, so the API can be used fluently
-
request
public <T> Future<Message<T>> request(String address, Object message)
Sends a message and specify areplyHandlerthat 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- the address to send it tomessage- the message body, may benull- Returns:
- a future notified when any reply from the recipient is received
-
rxRequest
public <T> Single<Message<T>> rxRequest(String address, Object message)
Sends a message and specify areplyHandlerthat 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- the address to send it tomessage- the message body, may benull- Returns:
- a future notified when any reply from the recipient is received
-
request
public <T> Future<Message<T>> request(String address, Object message, DeliveryOptions options)
Likerequest(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.- Parameters:
address- the address to send it tomessage- the message body, may benulloptions- delivery options- Returns:
- a future notified when any reply from the recipient is received
-
rxRequest
public <T> Single<Message<T>> rxRequest(String address, Object message, DeliveryOptions options)
Likerequest(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.- Parameters:
address- the address to send it tomessage- the message body, may benulloptions- delivery options- Returns:
- a future notified when any reply from the recipient is received
-
publish
public EventBus publish(String address, Object message)
Publish a message.The message will be delivered to all handlers registered to the address.
- Parameters:
address- the address to publish it tomessage- the message, may benull- Returns:
- a reference to this, so the API can be used fluently
-
publish
public EventBus publish(String address, Object message, DeliveryOptions options)
Likepublish(java.lang.String, java.lang.Object)but specifyingoptionsthat can be used to configure the delivery.- Parameters:
address- the address to publish it tomessage- the message, may benulloptions- the delivery options- Returns:
- a reference to this, so the API can be used fluently
-
consumer
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<io.vertx.reactivex.core.eventbus.Message<T>>)is called.- Parameters:
options- the consumer options- Returns:
- the event bus message consumer
-
consumer
public <T> MessageConsumer<T> consumer(MessageConsumerOptions options, Handler<Message<T>> handler)
Create a consumer and register it against the specified options address.- Parameters:
options- the consumer optionshandler- the handler that will process the received messages- Returns:
- the event bus message consumer
-
consumer
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<io.vertx.reactivex.core.eventbus.Message<T>>)is called.- Parameters:
address- the address that it will register it at- Returns:
- the event bus message consumer
-
consumer
public <T> MessageConsumer<T> consumer(String address, Handler<Message<T>> handler)
Create a consumer and register it against the specified address.- Parameters:
address- the address that will register it athandler- the handler that will process the received messages- Returns:
- the event bus message consumer
-
localConsumer
public <T> MessageConsumer<T> localConsumer(String address)
Likeconsumer(io.vertx.core.eventbus.MessageConsumerOptions)but the address won't be propagated across the cluster.- Parameters:
address- the address to register it at- Returns:
- the event bus message consumer
-
localConsumer
public <T> MessageConsumer<T> localConsumer(String address, Handler<Message<T>> handler)
Likeconsumer(io.vertx.core.eventbus.MessageConsumerOptions)but the address won't be propagated across the cluster.- Parameters:
address- the address that will register it athandler- the handler that will process the received messages- Returns:
- the event bus message consumer
-
sender
public <T> MessageProducer<T> sender(String address)
Create a message sender against the specified address.The returned sender will invoke the
send(java.lang.String, java.lang.Object)method when the streamWriteStream.write(T)method is called with the sender address and the provided data.- Parameters:
address- the address to send it to- Returns:
- The sender
-
sender
public <T> MessageProducer<T> sender(String address, DeliveryOptions options)
Likesender(java.lang.String)but specifying delivery options that will be used for configuring the delivery of the message.- Parameters:
address- the address to send it tooptions- the delivery options- Returns:
- The sender
-
publisher
public <T> MessageProducer<T> publisher(String address)
Create a message publisher against the specified address.The returned publisher will invoke the
publish(java.lang.String, java.lang.Object)method when the streamWriteStream.write(T)method is called with the publisher address and the provided data.- Parameters:
address- The address to publish it to- Returns:
- The publisher
-
publisher
public <T> MessageProducer<T> publisher(String address, DeliveryOptions options)
Likepublisher(java.lang.String)but specifying delivery options that will be used for configuring the delivery of the message.- Parameters:
address- the address to publish it tooptions- the delivery options- Returns:
- The publisher
-
codecSelector
public EventBus codecSelector(Function<Object,String> selector)
Set selector to be invoked when the bus has not found any codec for aMessagebody.The selector must return the name of a codec which has been registered with either
registerCodec(io.vertx.core.eventbus.MessageCodec)orio.vertx.reactivex.core.eventbus.EventBus#registerDefaultCodec.- Parameters:
selector- the codec selector- Returns:
- a reference to this, so the API can be used fluently
-
addOutboundInterceptor
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- the interceptor- Returns:
- a reference to this, so the API can be used fluently
-
removeOutboundInterceptor
public <T> EventBus removeOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Remove an interceptor that was added byaddOutboundInterceptor(io.vertx.core.Handler<io.vertx.reactivex.core.eventbus.DeliveryContext<T>>)- Parameters:
interceptor- the interceptor- Returns:
- a reference to this, so the API can be used fluently
-
addInboundInterceptor
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- the interceptor- Returns:
- a reference to this, so the API can be used fluently
-
removeInboundInterceptor
public <T> EventBus removeInboundInterceptor(Handler<DeliveryContext<T>> interceptor)
Remove an interceptor that was added byaddInboundInterceptor(io.vertx.core.Handler<io.vertx.reactivex.core.eventbus.DeliveryContext<T>>)- Parameters:
interceptor- the interceptor- Returns:
- a reference to this, so the API can be used fluently
-
clusterSerializableChecker
public EventBus clusterSerializableChecker(Function<String,Boolean> classNamePredicate)
Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded asClusterSerializable.This is only used when Vert.x is clustered.
- Parameters:
classNamePredicate- the predicate- Returns:
- a reference to this, so the API can be used fluently
-
serializableChecker
public EventBus serializableChecker(Function<String,Boolean> classNamePredicate)
Register a predicate to invoke when verifying if an object is allowed to be encoded/decoded asSerializable.This is only used when Vert.x is clustered.
- Parameters:
classNamePredicate- the predicate- Returns:
- a reference to this, so the API can be used fluently
-
registerCodec
public EventBus registerCodec(MessageCodec 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- the message codec to register- Returns:
- a reference to this, so the API can be used fluently
-
unregisterCodec
public EventBus unregisterCodec(String name)
Unregister a message codec.- Parameters:
name- the name of the codec- Returns:
- a reference to this, so the API can be used fluently
-
-