@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!")); } }
public static StaticHandler newInstance(io.vertx.ext.web.handler.StaticHandler arg) { return arg != null ? new StaticHandler(arg) : null; } }
/** * Create a handler using defaults * @return the handler */ public static io.vertx.rxjava.ext.web.handler.StaticHandler create() { io.vertx.rxjava.ext.web.handler.StaticHandler ret = io.vertx.rxjava.ext.web.handler.StaticHandler.newInstance(io.vertx.ext.web.handler.StaticHandler.create()); return ret; }
public static StaticHandler newInstance(io.vertx.ext.web.handler.StaticHandler arg) { return arg != null ? new StaticHandler(arg) : null; } }
/** * Create a handler, specifying web-root * @param root the web-root * @return the handler */ public static io.vertx.rxjava.ext.web.handler.StaticHandler create(String root) { io.vertx.rxjava.ext.web.handler.StaticHandler ret = io.vertx.rxjava.ext.web.handler.StaticHandler.newInstance(io.vertx.ext.web.handler.StaticHandler.create(root)); return ret; }
thread = new LunarThread(holder, context, new StaticHandler(this));
private void configureStaticHandler(VertxFactory vertxFactory, Router router) { if (vertxFactory.router().isStaticHandlerDefined()) { Route staticRoute; if (vertxFactory.router().staticHandler().path() != null) { staticRoute = router.route(vertxFactory.router().staticHandler().path()); } else { staticRoute = router.route(); } staticRoute.handler(vertxFactory.router().staticHandler().root() != null ? StaticHandler.create(vertxFactory.router().staticHandler().root()) : StaticHandler.create()); } } }
/** * Create a handler using defaults * @return the handler */ public static io.vertx.rxjava.ext.web.handler.StaticHandler create() { io.vertx.rxjava.ext.web.handler.StaticHandler ret = io.vertx.rxjava.ext.web.handler.StaticHandler.newInstance(io.vertx.ext.web.handler.StaticHandler.create()); return ret; }
/** * Create a handler, specifying web-root * @param root the web-root * @return the handler */ public static io.vertx.rxjava.ext.web.handler.StaticHandler create(String root) { io.vertx.rxjava.ext.web.handler.StaticHandler ret = io.vertx.rxjava.ext.web.handler.StaticHandler.newInstance(io.vertx.ext.web.handler.StaticHandler.create(root)); return ret; }