use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class EventBusExamples method example14.
public void example14() {
VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setClusterPublicHost("whatever").setClusterPublicPort(1234));
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 example2.
public void example2(Vertx vertx) {
EventBus eb = vertx.eventBus();
MessageConsumer<String> consumer = eb.consumer("news.uk.sport");
consumer.handler(message -> {
System.out.println("I have received a message: " + message.body());
});
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class MetricsTest method testReplyFailureRecipientFailure.
@Test
public void testReplyFailureRecipientFailure() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
EventBus eb = vertx.eventBus();
FakeEventBusMetrics metrics = FakeMetricsBase.getMetrics(eb);
AtomicReference<String> replyAddress = new AtomicReference<>();
CountDownLatch regLatch = new CountDownLatch(1);
eb.consumer("foo", msg -> {
replyAddress.set(msg.replyAddress());
msg.fail(0, "whatever");
}).completionHandler(onSuccess(v -> {
regLatch.countDown();
}));
awaitLatch(regLatch);
eb.send("foo", "bar", new DeliveryOptions(), ar -> {
assertTrue(ar.failed());
latch.countDown();
});
awaitLatch(latch);
assertEquals(Collections.singletonList(replyAddress.get()), metrics.getReplyFailureAddresses());
assertEquals(Collections.singletonList(ReplyFailure.RECIPIENT_FAILURE), metrics.getReplyFailures());
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class MetricsTest method testReplyFailureNoHandlers.
@Test
public void testReplyFailureNoHandlers() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
EventBus eb = vertx.eventBus();
eb.send(ADDRESS1, "bar", new DeliveryOptions().setSendTimeout(10), ar -> {
assertTrue(ar.failed());
latch.countDown();
});
awaitLatch(latch);
FakeEventBusMetrics metrics = FakeMetricsBase.getMetrics(eb);
assertEquals(Collections.singletonList(ADDRESS1), metrics.getReplyFailureAddresses());
assertEquals(Collections.singletonList(ReplyFailure.NO_HANDLERS), metrics.getReplyFailures());
}
use of io.vertx.core.eventbus.EventBus in project vert.x by eclipse.
the class MetricsContextTest method testEventBusLifecycle.
@Test
public void testEventBusLifecycle() {
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (vertx, options) -> new DummyVertxMetrics() {
@Override
public EventBusMetrics createMetrics(EventBus eventBus) {
return new DummyEventBusMetrics() {
@Override
public boolean isEnabled() {
return true;
}
@Override
public void close() {
closeCalled.set(true);
}
};
}
};
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
vertx.eventBus();
executeInVanillaThread(() -> {
vertx.close(onSuccess(v -> {
assertTrue(closeCalled.get());
testComplete();
}));
});
await();
}
Aggregations