Class EventBus

  • All Implemented Interfaces:
    Measured

    public class EventBus
    extends Object
    implements 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 original non RX-ified interface using Vert.x codegen.

    • Constructor Detail

      • EventBus

        public EventBus​(EventBus delegate)
      • EventBus

        public EventBus​(Object delegate)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isMetricsEnabled

        public boolean isMetricsEnabled()
        Whether the metrics are enabled for this measured object
        Specified by:
        isMetricsEnabled in interface Measured
        Returns:
        true if 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 to
        message - the message, may be null
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public EventBus send​(String address,
                             Object message,
                             DeliveryOptions options)
        Like send(java.lang.String, java.lang.Object) but specifying options that can be used to configure the delivery.
        Parameters:
        address - the address to send it to
        message - the message, may be null
        options - delivery options
        Returns:
        a reference to this, so the API can be used fluently
      • request

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

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

        Parameters:
        address - the address to send it to
        message - the message body, may be null
        replyHandler - reply handler will be called when any reply from the recipient is received
        Returns:
        a reference to this, so the API can be used fluently
      • request

        public <T> EventBus request​(String address,
                                    Object message)
        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 - the address to send it to
        message - the message body, may be null
        Returns:
        a reference to this, so the API can be used fluently
      • rxRequest

        public <T> io.reactivex.Single<Message<T>> rxRequest​(String address,
                                                             Object message)
        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 - the address to send it to
        message - the message body, may be null
        Returns:
        a reference to this, so the API can be used fluently
      • 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 to
        message - the message, may be null
        Returns:
        a reference to this, so the API can be used fluently
      • publish

        public EventBus publish​(String address,
                                Object message,
                                DeliveryOptions options)
        Like publish(java.lang.String, java.lang.Object) but specifying options that can be used to configure the delivery.
        Parameters:
        address - the address to publish it to
        message - the message, may be null
        options - the delivery options
        Returns:
        a reference to this, so the API can be used fluently
      • 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 at
        handler - the handler that will process the received messages
        Returns:
        the event bus message consumer
      • localConsumer

        public <T> MessageConsumer<T> localConsumer​(String address)
        Like consumer(java.lang.String) 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)
        Like consumer(java.lang.String) but the address won't be propagated across the cluster.
        Parameters:
        address - the address that will register it at
        handler - the handler that will process the received messages
        Returns:
        the event bus message consumer
      • sender

        public <T> MessageProducer<T> sender​(String address,
                                             DeliveryOptions options)
        Like sender(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 to
        options - the delivery options
        Returns:
        The sender
      • publisher

        public <T> MessageProducer<T> publisher​(String address,
                                                DeliveryOptions options)
        Like publisher(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 to
        options - 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 a Message body.

        The selector must return the name of a codec which has been registered with either registerCodec(io.vertx.core.eventbus.MessageCodec) or io.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
      • 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
      • clusterSerializableChecker

        public EventBus clusterSerializableChecker​(Function<String,​Boolean> classNamePredicate)
        Register a predicate to invoke when verifying if an object is forbidden to be encoded/decoded as ClusterSerializable.

        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 as Serializable.

        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