Class EventBusHandler
- java.lang.Object
-
- org.swisspush.gateleen.core.configuration.ConfigurationResourceConsumer
-
- org.swisspush.gateleen.core.event.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]
-
-
Field Summary
Fields Modifier and Type Field Description static intACCEPTEDstatic StringAPPLICATION_JSONstatic intBAD_REQUESTstatic StringCONTENT_TYPEstatic intGATEWAY_TIMEOUTstatic StringHEADERSstatic StringMETHODstatic StringPAYLOADstatic StringSYNCstatic StringTEXTstatic intTIMEOUTstatic StringURI
-
Constructor Summary
Constructors Constructor Description EventBusHandler(io.vertx.core.Vertx vertx, String apiPath, String sockPath, String addressPrefix, String addressPathPattern)EventBusHandler(io.vertx.core.Vertx vertx, String apiPath, String sockPath, String addressPrefix, String addressPathPattern, ConfigurationResourceManager configurationResourceManager, String configResourceUri)Constructs and configures the handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.vertx.ext.web.handler.sockjs.SockJSHandlerOptionsgetSockJSHandlerOptions()booleanhandle(io.vertx.core.http.HttpServerRequest request)voidinstall(io.vertx.ext.web.Router router)Configures and binds the SockJS bridge to an HttpServer.voidresourceChanged(String resourceUri, io.vertx.core.buffer.Buffer resource)Gets called when the resource with uriresourceUrihas been changed.voidresourceRemoved(String resourceUri)Gets called when the resource with uriresourceUrihas been removed.voidsetEventbusBridgeMaxAddressLength(Integer eventbusBridgeMaxAddressLength)Sets the maximum address length passed to the eventbus bridge.voidsetEventbusBridgeMaxHandlersPerSocket(Integer eventbusBridgeMaxHandlersPerSocket)Sets the max handlers per socket passed to the eventbus bridge.voidsetEventbusBridgePingInterval(Long eventbusBridgePingInterval)Sets the ping_interval passed to the eventbus bridge.voidsetEventbusBridgeReplyTimeout(Long eventbusBridgeReplyTimeout)Sets the reply timeout passed to the eventbus bridge.voidsetSockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions sockJSHandlerOptions)Sets theSockJSHandlerOptionsto be used for the websocket connections.-
Methods inherited from class org.swisspush.gateleen.core.configuration.ConfigurationResourceConsumer
configResourceUri, configurationResourceManager, schemaResourceName
-
-
-
-
Field Detail
-
ACCEPTED
public static final int ACCEPTED
- See Also:
- Constant Field Values
-
SYNC
public static final String SYNC
- See Also:
- Constant Field Values
-
TEXT
public static final String TEXT
- See Also:
- Constant Field Values
-
METHOD
public static final String METHOD
- See Also:
- Constant Field Values
-
BAD_REQUEST
public static final int BAD_REQUEST
- See Also:
- Constant Field Values
-
CONTENT_TYPE
public static final String CONTENT_TYPE
- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final String APPLICATION_JSON
- See Also:
- Constant Field Values
-
PAYLOAD
public static final String PAYLOAD
- See Also:
- Constant Field Values
-
URI
public static final String URI
- See Also:
- Constant Field Values
-
HEADERS
public static final String HEADERS
- See Also:
- Constant Field Values
-
TIMEOUT
public static final int TIMEOUT
- See Also:
- Constant Field Values
-
GATEWAY_TIMEOUT
public static final int GATEWAY_TIMEOUT
- See Also:
- Constant Field Values
-
-
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- vertxapiPath- 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 patternhello/(world/[^/]+)/.*will forward requests on/context/server/event/v1/hello/world/foo/barto addressevent/world/foo.configurationResourceManager- The ConfigurationResourceManager used to get notifications on resource updatesconfigResourceUri- 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:ConfigurationResourceObserverGets called when the resource with uriresourceUrihas been changed. The changed resource is provided in theresourceparameter.- Parameters:
resourceUri- the uri of the resource that has been changedresource- the resource including the changes
-
resourceRemoved
public void resourceRemoved(String resourceUri)
Description copied from interface:ConfigurationResourceObserverGets called when the resource with uriresourceUrihas 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 callinginstall(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 callinginstall(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 callinginstall(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 callinginstall(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 theSockJSHandlerOptionsto be used for the websocket connections. Set these options before callinginstall(io.vertx.ext.web.Router)- Parameters:
sockJSHandlerOptions-SockJSHandlerOptionsto be used. DefaultSockJSHandlerOptionsare used when null provided
-
getSockJSHandlerOptions
public io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions getSockJSHandlerOptions()
-
-