title: Bridging messages from eventbus to subscribed websocket clients using VertX
body: <p>I'm trying to use websocket to create a publish-suscribe model which can be reached through both SockJS and Websocket (for Javascript clients on one side, and for Java clients on the other. </p>
  
  <p>Currently I'm able to subscribe using SockJS and Javascript clients. However, when trying to use websocket to receive messages in my Java client, I am able to connect to the websocket server, but don't receive any messages from the server.</p>
  
  <p>My current client code:</p>
  
  <pre><code>public class WebsocketReceiverIntegrationTest {
      public static void main(String[] args) {
          System.out.println("Started demo WS client");
          HttpClient client = Vertx.vertx().createHttpClient();
  
          System.out.println("Will now connect to WS server");
          client.websocket(8091, "localhost", "/", webSocket -&gt; {
             webSocket.handler( data -&gt; {
                  System.out.print("Received data " + data.toString("ISO-8859-1"));
             });
          });
  
          System.out.println("Ready to receive data");
  
          Scanner scanner = new Scanner(System.in);
          while (scanner.hasNext() &amp;&amp; ! scanner.next().equals("q")) {
          }
  
          System.out.println("Stopped");
          client.close();
      }
  }
  </code></pre>
  
  <p>Relevant bit in my current server code:</p>
  
  <pre><code>@Override
  public void start(Future&lt;Void&gt; fut) {
      Router router = Router.router(vertx);
  
      router.route("/eventbus/*").handler(sockJSEventBusHandler());
  
      router.route().failureHandler(errorHandler());
  
      vertx.createHttpServer().websocketHandler(serverWebSocket -&gt; {
          System.out.print("Websocket client connected!");
          vertx.eventBus().consumer(serverWebSocket.textHandlerID());
      }).listen(8091);
  
      vertx.setPeriodic(1000, id -&gt; {
          vertx.eventBus().send("gameupdates", Json.encodePrettily(tickGameState()));
      });
  }
  
  private SockJSHandler sockJSEventBusHandler() {
      BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress(GAMEUPDATE_CHANNEL_NAME));
      return SockJSHandler.create(vertx).bridge(options, event -&gt; {
          if (event.type() == BridgeEventType.SOCKET_CREATED) {
              logger.info("A socket was created");
          }
          event.complete(true);
      });
  }
  </code></pre>