Class EventBusHandler

  • All Implemented Interfaces:
    ConfigurationResourceObserver

    public class EventBusHandler
    extends ConfigurationResourceConsumer
    Delivers a request on the event bus.

    If the header "x-sync" is set to "true", then the handler waits for an event reply before returning the response. In this case, the response contains the replied JSON, if any.

    Requests are forwarded in the form:

     {
         "uri": "http://...",
         "method": "PUT",
         "headers": [
              [ "name", "value" ],
              [ "name", "value" ]
         ],
         "payload": {
             "hello": "world"
         }
     }
     
    Payload is a JsonObject in case of application/json content type, a string in case of text/* content type, a base64 binary string otherwise.

    Replies from clients have the same structure, without the uri.1

    Author:
    https://github.com/lbovet [Laurent Bovet]
    • Constructor Detail

      • EventBusHandler

        public EventBusHandler​(io.vertx.core.Vertx vertx,
                               String apiPath,
                               String sockPath,
                               String addressPrefix,
                               String addressPathPattern)
      • EventBusHandler

        public EventBusHandler​(io.vertx.core.Vertx vertx,
                               String apiPath,
                               String sockPath,
                               String addressPrefix,
                               String addressPathPattern,
                               ConfigurationResourceManager configurationResourceManager,
                               String configResourceUri)
        Constructs and configures the handler.
        Parameters:
        vertx - vertx
        apiPath - The full URI path where to access the event api. E.g. /context/server/event/v1/.
        sockPath - The full URI path of the SockJS endpoint to configure.
        addressPrefix - The prefix used for the event bus addresses the handlers sends requests to. E.g. event/
        addressPathPattern - A pattern to extract the address from the URI. This pattern is appended to the apiPath and must have a group. For example, a pattern hello/(world/[^/]+)/.* will forward requests on /context/server/event/v1/hello/world/foo/bar to address event/world/foo.
        configurationResourceManager - The ConfigurationResourceManager used to get notifications on resource updates
        configResourceUri - The full URI path of the configuration resource
    • Method Detail

      • handle

        public boolean handle​(io.vertx.core.http.HttpServerRequest request)
      • install

        public void install​(io.vertx.ext.web.Router router)
        Configures and binds the SockJS bridge to an HttpServer.
        Parameters:
        router - router
      • resourceChanged

        public void resourceChanged​(String resourceUri,
                                    io.vertx.core.buffer.Buffer resource)
        Description copied from interface: ConfigurationResourceObserver
        Gets called when the resource with uri resourceUri has been changed. The changed resource is provided in the resource parameter.
        Parameters:
        resourceUri - the uri of the resource that has been changed
        resource - the resource including the changes
      • resourceRemoved

        public void resourceRemoved​(String resourceUri)
        Description copied from interface: ConfigurationResourceObserver
        Gets called when the resource with uri resourceUri has been removed.
        Parameters:
        resourceUri - the uri of the resource that has been removed
      • setEventbusBridgePingInterval

        public void setEventbusBridgePingInterval​(Long eventbusBridgePingInterval)
        Sets the ping_interval passed to the eventbus bridge. Defines the interval before a websocket connection is closed if no interaction with client happens in the meantime. Set the interval before calling install(io.vertx.ext.web.Router)
        Parameters:
        eventbusBridgePingInterval - Interval in milliseconds or null to use the default interval of the eventbus bridge (10 seconds)
      • setEventbusBridgeReplyTimeout

        public void setEventbusBridgeReplyTimeout​(Long eventbusBridgeReplyTimeout)
        Sets the reply timeout passed to the eventbus bridge. Set the interval before calling install(io.vertx.ext.web.Router)
        Parameters:
        eventbusBridgeReplyTimeout - Timeout in milliseconds or null to use the default reply timeout of the eventbus bridge (30 seconds)
      • setEventbusBridgeMaxAddressLength

        public void setEventbusBridgeMaxAddressLength​(Integer eventbusBridgeMaxAddressLength)
        Sets the maximum address length passed to the eventbus bridge. Set the interval before calling install(io.vertx.ext.web.Router)
        Parameters:
        eventbusBridgeMaxAddressLength - Maximum address length or null to use the default value of the eventbus bridge (200)
      • setEventbusBridgeMaxHandlersPerSocket

        public void setEventbusBridgeMaxHandlersPerSocket​(Integer eventbusBridgeMaxHandlersPerSocket)
        Sets the max handlers per socket passed to the eventbus bridge. Set the interval before calling install(io.vertx.ext.web.Router)
        Parameters:
        eventbusBridgeMaxHandlersPerSocket - Maximum handlers per socket or null to use the default value of the eventbus bridge (1000)
      • setSockJSHandlerOptions

        public void setSockJSHandlerOptions​(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions sockJSHandlerOptions)
        Sets the SockJSHandlerOptions to be used for the websocket connections. Set these options before calling install(io.vertx.ext.web.Router)
        Parameters:
        sockJSHandlerOptions - SockJSHandlerOptions to be used. Default SockJSHandlerOptions are used when null provided
      • getSockJSHandlerOptions

        public io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions getSockJSHandlerOptions()