Class EventBusHandler

  • All Implemented Interfaces:
    Handler<Response>

    public class EventBusHandler
    extends Object
    implements Handler<Response>
    A handler that can be installed on a Redis connection using RedisConnection.handler(Handler) in order to consume subscription messages and send them on the Vert.x event bus.

    The message sent to the Vert.x event bus is a JsonObject with the following format:

     {
       "status": "OK",
       "type": "message|subscribe|unsubscribe|pmessage|psubscribe|punsubscribe",
       "value": {
         "channel": "<the channel>", // for `[p]message`, `subscribe` and `unsubscribe`
         "message": "<the message>", // for `[p]message`
         "pattern": "<the pattern>", // for `pmessage`, `psubscribe` and `punsubscribe`
         "current": <number of current subscriptions> // for `[p]subscribe` and `[p]unsubscribe`
       }
     }
     
    By default, the address to which the messages are sent is io.vertx.redis.<the channel>. This can be changed by passing a different address prefix to create(Vertx, String). For example, if the prefix is com.example, the address is com.example.<the channel>.

    Note that for messages of types psubscribe and punsubscribe, there is no channel name. Therefore, these messages are sent to the address of <prefix>.<the pattern>.

    • Method Detail

      • create

        public static EventBusHandler create​(Vertx vertx)
        Creates a subscription handler that forwards messages to the event bus of the given vertx. The default address prefix is used.
      • create

        public static EventBusHandler create​(Vertx vertx,
                                             String addressPrefix)
        Creates a subscription handler that forwards messages to the event bus of the given vertx. The given address prefix is used.
      • handle

        public void handle​(Response reply)
        Description copied from interface: Handler
        Something has happened, so handle it.
        Specified by:
        handle in interface Handler<Response>
        Parameters:
        reply - the event to handle