@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!")); } }
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket event) { delegate.handle(event.getDelegate()); }
public void handle(io.vertx.ext.web.handler.sockjs.SockJSSocket event) { handler.handle(io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(event)); } });
public static SockJSSocket newInstance(io.vertx.ext.web.handler.sockjs.SockJSSocket arg) { return arg != null ? new SockJSSocket(arg) : null; } }
ar.result().getRegistration() + "]...\n"); this.registrations.put(bridgeEvent.socket().writeHandlerID(), ar.result().getRegistration()); String writeHandlerID = bridgeEvent.socket().writeHandlerID();
@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; } }
public synchronized io.vertx.rx.java.WriteStreamSubscriber<io.vertx.rxjava.core.buffer.Buffer> toSubscriber() { if (subscriber == null) { java.util.function.Function<io.vertx.rxjava.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate; subscriber = io.vertx.rx.java.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
public void handle(io.vertx.ext.web.handler.sockjs.SockJSSocket event) { handler.handle(io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(event)); } });
public static SockJSSocket newInstance(io.vertx.ext.web.handler.sockjs.SockJSSocket arg) { return arg != null ? new SockJSSocket(arg) : null; } }
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket event) { delegate.handle(event.getDelegate()); }
/** * Get the SockJSSocket instance corresponding to the event * @return the SockJSSocket instance */ public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket socket() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(delegate.socket()); cached_1 = ret; return ret; }
public synchronized io.vertx.rx.java.WriteStreamSubscriber<io.vertx.rxjava.core.buffer.Buffer> toSubscriber() { if (subscriber == null) { java.util.function.Function<io.vertx.rxjava.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate; subscriber = io.vertx.rx.java.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
/** * Get the SockJSSocket instance corresponding to the event * @return the SockJSSocket instance */ public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket socket() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(delegate.socket()); cached_1 = ret; return ret; }