@Override public void send(Object data) { vertx.eventBus().send(address, data); }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxSend} instead */ @Deprecated() public <T> Observable<io.vertx.rxjava.core.eventbus.Message<T>> sendObservable(String address, Object message) { io.vertx.rx.java.ObservableFuture<io.vertx.rxjava.core.eventbus.Message<T>> replyHandler = io.vertx.rx.java.RxHelper.observableFuture(); send(address, message, replyHandler.toHandler()); return replyHandler; }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @param options delivery options * @return a reference to this, so the API can be used fluently */ public <T> Single<io.vertx.rxjava.core.eventbus.Message<T>> rxSend(String address, Object message, DeliveryOptions options) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { send(address, message, options, fut); })); }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @return a reference to this, so the API can be used fluently */ public <T> Single<io.vertx.rxjava.core.eventbus.Message<T>> rxSend(String address, Object message) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { send(address, message, fut); })); }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @param options delivery options * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxSend} instead */ @Deprecated() public <T> Observable<io.vertx.rxjava.core.eventbus.Message<T>> sendObservable(String address, Object message, DeliveryOptions options) { io.vertx.rx.java.ObservableFuture<io.vertx.rxjava.core.eventbus.Message<T>> replyHandler = io.vertx.rx.java.RxHelper.observableFuture(); send(address, message, options, replyHandler.toHandler()); return replyHandler; }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @return a reference to this, so the API can be used fluently */ public <T> Single<io.vertx.rxjava.core.eventbus.Message<T>> rxSend(String address, Object message) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { send(address, message, fut); })); }
/** * Like {@link io.vertx.rxjava.core.eventbus.EventBus#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param address the address to send it to * @param message the message, may be <code>null</code> * @param options delivery options * @return a reference to this, so the API can be used fluently */ public <T> Single<io.vertx.rxjava.core.eventbus.Message<T>> rxSend(String address, Object message, DeliveryOptions options) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { send(address, message, options, fut); })); }
@Override public void start() throws Exception { ServiceDiscovery discovery = ServiceDiscovery.create(vertx, DISCOVERY_OPTIONS); io.vertx.rxjava.servicediscovery.types.EventBusService.getServiceProxyWithJsonFilter( discovery, new JsonObject().put("service.interface", io.vertx.it.service.HelloService.class.getName()), HelloService.class, // service interface ar -> { if (ar.failed()) { vertx.eventBus().send("result", new JsonObject().put("status", "ko").put("message", ar.cause().getMessage())); } else { HelloService hello = ar.result(); hello.hello(new JsonObject().put("name", "vert.x"), result -> { if (result.failed()) { vertx.eventBus().send("result", new JsonObject() .put("status", "ko") .put("message", result.cause().getMessage())); } else { vertx.eventBus().send("result", new JsonObject() .put("status", "ok") .put("message", result.result())); ServiceDiscovery.releaseServiceObject(discovery, hello); } }); } }); }
@Override public void onNext(String s) { assertEquals("msg1", s); unsubscribe(); assertFalse(consumer.isRegistered()); obs.subscribe(new Subscriber<String>() { @Override public void onNext(String s) { assertEquals("msg2", s); unsubscribe(); assertFalse(consumer.isRegistered()); testComplete(); } @Override public void onError(Throwable throwable) { fail("Was not esxpecting error " + throwable.getMessage()); } @Override public void onCompleted() { fail(); } }); eb.send("the-address", "msg2"); }
@Test public void testObservableUnsubscribeDuringObservation() { EventBus eb = vertx.eventBus(); MessageConsumer<String> consumer = eb.<String>consumer("the-address"); Observable<String> obs = consumer.bodyStream().toObservable(); Observable<String> a = obs.take(4); List<String> obtained = new ArrayList<>(); a.subscribe(new Subscriber<String>() { @Override public void onCompleted() { assertEquals(Arrays.asList("msg0", "msg1", "msg2", "msg3"), obtained); testComplete(); } @Override public void onError(Throwable e) { fail(e.getMessage()); } @Override public void onNext(String str) { obtained.add(str); } }); for (int i = 0; i < 7; i++) { eb.send("the-address", "msg" + i); } await(); }
@Test public void testConcatReplies() { EventBus eb = vertx.eventBus(); eb.<String>consumer("the-address", msg -> { msg.reply(msg.body()); }); Single<Message<String>> obs1 = eb.rxSend("the-address", "msg1"); Single<Message<String>> obs2 = eb.rxSend("the-address", "msg2"); eb.send("the-address", "done", reply -> { Observable<Message<String>> all = Single.concat(obs1, obs2); LinkedList<String> values = new LinkedList<String>(); all.subscribe(next -> { values.add(next.body()); }, err -> { fail(); }, () -> { assertEquals(Arrays.asList("msg1", "msg2"), values); testComplete(); }); }); await(); }
eb.send("the-address", "msg1"); await();