@Override public void start() throws Exception { Router router = Router.router(vertx); router.route("/news-feed/*").handler(SockJSHandler.create(vertx).socketHandler(sockJSSocket -> { // Consumer the event bus address as an Observable Observable<String> msg = vertx.eventBus().<String>consumer("news-feed") .bodyStream() .toObservable(); // Send the event to the client Subscription subscription = msg.subscribe(sockJSSocket::write); // Unsubscribe when the socket closes sockJSSocket.endHandler(v -> { subscription.unsubscribe(); }); })); // Serve the static resources router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); // Publish a message to the address "news-feed" every second vertx.setPeriodic(1000, t -> vertx.eventBus().publish("news-feed", "news from the server!")); } }
@Bean public SockJSHandler sockJSHandler() { EventBusBridgeEvents eventBusBridgeEvents = eventBusBridgeEvents(); SockJSHandler sockJSHandler = SockJSHandler.create(vertx); BridgeOptions options = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddressRegex(eventBusBridgeEvents.toIncomingEventName(".*"))) .addOutboundPermitted(new PermittedOptions().setAddressRegex(eventBusBridgeEvents.toOutgoingEventName(".*"))); sockJSHandler.bridge(options, event -> { if (event.type() == BridgeEventType.SOCKET_CREATED) { if (log.isDebugEnabled()) { log.debug("Socket connection created {}", event.socket().remoteAddress().host()); } } event.complete(true); }); return sockJSHandler; } }
/** * Create a SockJS handler * @param vertx the Vert.x instance * @return the handler */ public static io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler.newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler.create(vertx.getDelegate())); return ret; }
public static SockJSHandler newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler arg) { return arg != null ? new SockJSHandler(arg) : null; } }
private void configureSockJS(VertxFactory vertxFactory, io.vertx.rxjava.core.Vertx rxVertx, Router router, BridgeOptions bridgeOptions, Handler<BridgeEvent> bridgeEventHandler) { if (vertxFactory.router().isSockJSHandlerDefined()) { SockJSHandler sjsHandler = SockJSHandler.create(rxVertx).bridge(bridgeOptions, bridgeEventHandler); Route sockJSRoute; if (vertxFactory.router().sockjs().path() != null) { sockJSRoute = router.route(vertxFactory.router().sockjs().path()); } else { sockJSRoute = router.route(); } sockJSRoute.handler(sjsHandler); } }
/** * Create a SockJS handler * @param vertx the Vert.x instance * @param options options to configure the handler * @return the handler */ public static io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler create(io.vertx.rxjava.core.Vertx vertx, SockJSHandlerOptions options) { io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler.newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler.create(vertx.getDelegate(), options)); return ret; }
public static SockJSHandler newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler arg) { return arg != null ? new SockJSHandler(arg) : null; } }
/** * Create a SockJS handler * @param vertx the Vert.x instance * @return the handler */ public static io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler.newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler.create(vertx.getDelegate())); return ret; }
/** * Create a SockJS handler * @param vertx the Vert.x instance * @param options options to configure the handler * @return the handler */ public static io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler create(io.vertx.rxjava.core.Vertx vertx, SockJSHandlerOptions options) { io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler.newInstance(io.vertx.ext.web.handler.sockjs.SockJSHandler.create(vertx.getDelegate(), options)); return ret; }