vertx.setPeriodic(1000, v -> {
@Override public void start() throws Exception { EventBus eb = vertx.eventBus(); eb.consumer(ADDRESS) .toObservable() .subscribe(message -> { System.out.println("Received " + message.body()); message.reply("PONG"); }); // Send a message every second vertx.setPeriodic(1000, v -> { eb.rxSend(ADDRESS, "PING") .subscribe(reply -> { System.out.println("Received reply " + reply.body()); }); }); } }
@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!")); } }
@Override public void start() throws Exception { if (config.isRefetchImmediatelyOnDeliveryWithMaxAmountOfNodes()) { this.subscriber = new BaseSubscriber<ConfirmedDeliveryEvent>() { @Override protected void hookOnNext(ConfirmedDeliveryEvent event) { try { onConfirmedDeliveryPackage(event); } catch (Exception e) { log.error("", e); } } }; xfcdEvents.subscribe(ConfirmedDeliveryEvent.class, this.subscriber); } this.initTimerId = vertx.setTimer(config.getInitialDelayInMs(), timerId -> { fetchDeliveriesAndPublishOnEventBus(); this.periodicTimerId = vertx.setPeriodic(config.getIntervalInMs(), foo -> { fetchDeliveriesAndPublishOnEventBus(); }); }); }