use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class EventBusTestBase method testReplyFromWorker.
@Test
public void testReplyFromWorker() throws Exception {
String expectedBody = TestUtils.randomAlphaString(20);
startNodes(2);
CountDownLatch latch = new CountDownLatch(1);
vertices[0].deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
vertices[1].eventBus().<String>consumer(ADDRESS1, msg -> {
msg.reply(expectedBody);
}).completionHandler(ar -> {
assertTrue(ar.succeeded());
latch.countDown();
});
}
}, new DeploymentOptions().setWorker(true));
awaitLatch(latch);
vertices[0].eventBus().send(ADDRESS1, "whatever", reply -> {
assertTrue(reply.succeeded());
assertEquals(expectedBody, reply.result().body());
testComplete();
});
await();
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class EventBusExamples method example12.
public void example12() {
VertxOptions options = new VertxOptions();
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
EventBus eventBus = vertx.eventBus();
System.out.println("We now have a clustered event bus: " + eventBus);
} else {
System.out.println("Failed: " + res.cause());
}
});
}
use of io.vertx.core.eventbus.EventBus in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeEchoServer method main.
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
EventBus eb = vertx.eventBus();
eb.consumer("hello", (Message<JsonObject> msg) -> {
msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value")));
});
eb.consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
eb.consumer("echo2", (Message<JsonObject> msg) -> {
if ("send".equals(msg.body().getString("response_type"))) {
eb.send("echo2_response", msg.body());
} else {
eb.publish("echo2_response", msg.body());
}
});
TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("echo2")).addOutboundPermitted(new PermittedOptions().setAddress("echo2_response")));
bridge.listen(7000, res -> System.out.println("Ready"));
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class EventBusExamples method example13.
public void example13() {
VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setSsl(true).setKeyStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setTrustStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setClientAuth(ClientAuth.REQUIRED));
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
EventBus eventBus = vertx.eventBus();
System.out.println("We now have a clustered event bus: " + eventBus);
} else {
System.out.println("Failed: " + res.cause());
}
});
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class EventBusExamples method example1.
public void example1(Vertx vertx) {
EventBus eb = vertx.eventBus();
eb.consumer("news.uk.sport", message -> {
System.out.println("I have received a message: " + message.body());
});
}
Aggregations