io.vertx.core.eventbus

## Interface EventBus

- All Superinterfaces:
    Measured

      public interface EventBus
      extends 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.

  Author:
    Tim Fox

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    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
    `<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 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` | `unregisterCodec(String name)` Unregister a message codec.
    `EventBus` | `unregisterDefaultCodec(Class clazz)` Unregister a default message codec.

    - ### Methods inherited from interface io.vertx.core.metrics.Measured

      `isMetricsEnabled`

- - ### Method Detail

    - #### send

          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

          EventBus send(String address,
                        Object message,
                        DeliveryOptions options)

      Like `send(String, 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

          default <T> EventBus request(String address,
                                       Object message,
                                       Handler<AsyncResult<Message<T>>> replyHandler)

      Sends a message and 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

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

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

    - #### request

          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.
      Parameters:
        `address` - the address to send it to
        `message` - the message body, may be `null`
        `options` - delivery options
        `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

          <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

    - #### publish

          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

          EventBus publish(String address,
                           Object message,
                           DeliveryOptions options)

      Like `publish(String, 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

          <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` - the address that it will register it at
      Returns:
        the event bus message consumer

    - #### consumer

          <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

          <T> MessageConsumer<T> localConsumer(String address)

      Like `consumer(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

          <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` - the address that will register it at
        `handler` - the handler that will process the received messages
      Returns:
        the event bus message consumer

    - #### sender

          <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 `WriteStream.write(Object)` method is called with the sender address and the provided data.

      Parameters:
        `address` - the address to send it to
      Returns:
        The sender

    - #### sender

          <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` - the address to send it to
        `options` - the delivery options
      Returns:
        The sender

    - #### publisher

          <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 `WriteStream.write(Object)` method is called with the publisher address and the provided data.

      Parameters:
        `address` - The address to publish it to
      Returns:
        The publisher

    - #### publisher

          <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` - the address to publish it to
        `options` - the delivery options
      Returns:
        The publisher

    - #### registerCodec

          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

          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

    - #### registerDefaultCodec

          <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` - the class for which to use this codec
        `codec` - the message codec to register
      Returns:
        a reference to this, so the API can be used fluently

    - #### unregisterDefaultCodec

          EventBus unregisterDefaultCodec(Class clazz)

      Unregister a default message codec.

      Parameters:
        `clazz` - the class for which the codec was registered
      Returns:
        a reference to this, so the API can be used fluently

    - #### addOutboundInterceptor

          <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

          <T> EventBus removeOutboundInterceptor(Handler<DeliveryContext<T>> interceptor)

      Remove an interceptor that was added by `addOutboundInterceptor(Handler)`
      Parameters:
        `interceptor` - the interceptor
      Returns:
        a reference to this, so the API can be used fluently

    - #### addInboundInterceptor

          <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

          <T> EventBus removeInboundInterceptor(Handler<DeliveryContext<T>> interceptor)

      Remove an interceptor that was added by `addInboundInterceptor(Handler)`
      Parameters:
        `interceptor` - the interceptor
      Returns:
        a reference to this, so the API can be used fluently

Copyright © 2021 Eclipse. All rights reserved.