Class EventbusTcpBridge

java.lang.Object
io.vertx.core.AbstractVerticle
de.wuespace.telestion.services.connection.EventbusTcpBridge
All Implemented Interfaces:
io.vertx.core.Verticle

public final class EventbusTcpBridge extends io.vertx.core.AbstractVerticle
EventbusTcpBridge is a verticle which uses SockJS-WebSockets to extend the vertx.eventBus() to an HTTP-Server.

It creates Router using vertx, which handles HTTP-Requests coming to the HTTP-Server. The EventBusBridge by default works after the deny-any-principle, which means that any message which is not permitted explicitly will be denied (reply messages are an exception). To permit the desired messages for the frontend to go through you have to configure SockJSBridgeOptions and mount them as a SubRouter to the Router.

You have to configure the following options:

  • httpServerOptions - the HttpServerOptions to configure the HTTP-Server
  • defaultSockJSBridgeOptions - the SockJSBridgeOptions to configure rules to allow messages to go through
To do that you have four constructors to initialize the HTTP-Server.

To define rules for messages to be allowed through you have to add new PermittedOptions() to the sockJSBridgeOptions. You can either do that in the third constructor by passing new SockJSBridgeOptions as parameter or modify the defaultSockJSBridgeOptions and add your rules there.

An example looks like this:

SockJSBridgeOptions defaultSockJSBridgeOptions = new SockJSBridgeOptions()
 	.addInboundPermitted(new PermittedOptions()
 	.setAddress(Address.incoming(<YourClass>.class, "<method>")))
 	.addOutboundPermitted(new PermittedOptions()
 	.setAddress(Address.outgoing(<YourClass>.class, "<method>)));

To support that the one can send data type specific data on the outbound address vertx supports regex. You can add a regex to new PermittedOptions().

An example looks like this:

SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions()
 	.addOutboundPermitted(new PermittedOptions().setAddressRegex("(<Address>)(\/(\S+))?"));
Which results in permission granted to all messages to the given address optionally suffixed with e.g. "/className.
See Also:
README.md for more information
  • Field Summary

    Fields inherited from class io.vertx.core.AbstractVerticle

    context, vertx
  • Constructor Summary

    Constructors
    Constructor
    Description
    If this constructor is used all, settings have to be specified in the config file.
    EventbusTcpBridge​(String host, int port, List<String> inboundPermitted, List<String> outboundPermitted)
    This constructor supplies default options and uses the defaultSockJSBridgeOptions for the applied rules.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    start​(io.vertx.core.Promise<Void> startPromise)
     

    Methods inherited from class io.vertx.core.AbstractVerticle

    config, deploymentID, getVertx, init, processArgs, start, stop, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventbusTcpBridge

      public EventbusTcpBridge(String host, int port, List<String> inboundPermitted, List<String> outboundPermitted)
      This constructor supplies default options and uses the defaultSockJSBridgeOptions for the applied rules.
      Parameters:
      host - the ip address of the host on which the HTTP-Server should run
      port - the port on which the HTTP-Server should listen
      inboundPermitted - the permitted eventbus addresses for inbound connections
      outboundPermitted - the permitted eventbus addresses for outbound connections
    • EventbusTcpBridge

      public EventbusTcpBridge()
      If this constructor is used all, settings have to be specified in the config file.
  • Method Details

    • start

      public void start(io.vertx.core.Promise<Void> startPromise)
      Specified by:
      start in interface io.vertx.core.Verticle
      Overrides:
      start in class io.vertx.core.AbstractVerticle