use of io.vertx.core.eventbus.ReplyException in project vert.x by eclipse.
the class EventBusTestBase method testNoHandlersCallbackContext.
@Test
public void testNoHandlersCallbackContext() {
startNodes(2);
waitFor(4);
// On an "external" thread
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertTrue("Not an EL thread", Context.isOnEventLoopThread());
complete();
});
// On a EL context
vertices[0].runOnContext(v -> {
Context ctx = vertices[0].getOrCreateContext();
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertSame(ctx, vertices[0].getOrCreateContext());
complete();
});
});
// On a Worker context
vertices[0].deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
Context ctx = getVertx().getOrCreateContext();
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertSame(ctx, getVertx().getOrCreateContext());
complete();
});
}
}, new DeploymentOptions().setWorker(true));
// Inside executeBlocking
vertices[0].executeBlocking(fut -> {
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertTrue("Not an EL thread", Context.isOnEventLoopThread());
complete();
});
fut.complete();
}, false, null);
await();
}
use of io.vertx.core.eventbus.ReplyException in project vert.x by eclipse.
the class FaultToleranceVerticle method ping.
private void ping(Message<JsonArray> message) {
JsonArray jsonArray = message.body();
for (int i = 0; i < jsonArray.size(); i++) {
int node = jsonArray.getInteger(i);
for (int j = 0; j < numAddresses; j++) {
vertx.eventBus().send(createAddress(node, j), "ping", ar -> {
if (ar.succeeded()) {
vertx.eventBus().send("control", "pong");
} else {
Throwable cause = ar.cause();
if (cause instanceof ReplyException) {
ReplyException replyException = (ReplyException) cause;
if (replyException.failureType() == ReplyFailure.NO_HANDLERS) {
vertx.eventBus().send("control", "noHandlers");
return;
}
}
log.error("Unexpected error during ping (id=" + id + ")", cause);
}
});
}
}
}
use of io.vertx.core.eventbus.ReplyException in project chili-core by codingchili.
the class BusRouter method send.
protected void send(Request request, String target) {
DeliveryOptions options = new DeliveryOptions().setSendTimeout(request.timeout());
core.bus().send(target, request.data(), options, send -> {
if (send.succeeded()) {
request.write(send.result().body());
} else {
Throwable exception = send.cause();
if (exception instanceof ReplyException) {
ReplyFailure status = ((ReplyException) exception).failureType();
exceptionHandlers.get(status).accept(request);
} else {
request.error(send.cause());
}
}
});
}
use of io.vertx.core.eventbus.ReplyException in project vertx-openshift-it by cescoffier.
the class SenderVerticle method setupRouter.
private Router setupRouter() {
Router router = Router.router(vertx);
router.get("/deliver-to-functional-pod").handler(rc -> {
vertx.eventBus().<String>send("foobar", "ping", ar -> {
if (ar.succeeded()) {
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/plain").end(ar.result().body());
} else {
ar.cause().printStackTrace();
rc.fail(500);
}
});
});
router.get("/deliver-to-failing-pod").handler(rc -> {
vertx.eventBus().<String>send("foobar", "ping", ar -> {
if (ar.failed() && ar.cause() instanceof ReplyException) {
ReplyException replyException = (ReplyException) ar.cause();
if (replyException.failureType() == ReplyFailure.NO_HANDLERS) {
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/plain").end("OK");
return;
}
}
rc.fail(500);
});
});
router.get("/health").handler(rc -> {
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/plain").end("OK");
});
return router;
}
use of io.vertx.core.eventbus.ReplyException in project vert.x by eclipse.
the class FaultToleranceVerticle method ping.
private void ping(Message<JsonArray> message) {
JsonArray jsonArray = message.body();
for (int i = 0; i < jsonArray.size(); i++) {
int node = jsonArray.getInteger(i);
for (int j = 0; j < numAddresses; j++) {
vertx.eventBus().request(createAddress(node, j), "ping", ar -> {
if (ar.succeeded()) {
vertx.eventBus().send("control", "pong");
} else {
Throwable cause = ar.cause();
if (cause instanceof ReplyException) {
ReplyException replyException = (ReplyException) cause;
if (replyException.failureType() == ReplyFailure.NO_HANDLERS) {
vertx.eventBus().send("control", "noHandlers");
return;
}
}
log.error("Unexpected error during ping (id=" + id + ")", cause);
}
});
}
}
}
Aggregations