use of io.vertx.core.eventbus.Message in project failsafe by jhalterman.
the class VertxExample method main.
/**
* A Vert.x sender and retryable receiver example.
*/
public static void main(String... args) throws Throwable {
// Receiver that fails 2 times then succeeds
AtomicInteger failures = new AtomicInteger();
vertx.eventBus().consumer("ping-address", message -> {
if (failures.getAndIncrement() < 2)
message.fail(1, "Failed");
else {
message.reply("pong!");
}
});
// Retryable sender
Failsafe.with(retryPolicy).with(scheduler).getAsyncExecution(execution -> vertx.eventBus().send("ping-address", "ping!", reply -> {
if (reply.succeeded())
execution.recordResult(reply.result());
else
execution.recordFailure(reply.cause());
}));
Thread.sleep(5000);
System.exit(0);
}
use of io.vertx.core.eventbus.Message in project chili-core by codingchili.
the class BusRouterTest method testRouteNodeTimeoutLogged.
@Test
public void testRouteNodeTimeoutLogged(TestContext test) {
Async async = test.async();
String node = UUID.randomUUID().toString();
mockNode(node, message -> {
});
handle(node, ((response, status) -> {
test.assertTrue(nodeTimeout.get());
async.complete();
}));
}
use of io.vertx.core.eventbus.Message in project chili-core by codingchili.
the class BusRouterTest method testTimeout.
@Test
public void testTimeout(TestContext test) {
Async async = test.async();
mockNode(NODE_1, (message) -> {
});
handle(NODE_1, ((response, status) -> {
test.assertEquals(ResponseStatus.ERROR, status);
test.assertTrue(response.getString(PROTOCOL_MESSAGE).contains(system().getClusterTimeout() + ""));
async.complete();
}));
}
Aggregations