本文整理汇总了Java中io.vertx.core.eventbus.ReplyFailure类的典型用法代码示例。如果您正苦于以下问题:Java ReplyFailure类的具体用法?Java ReplyFailure怎么用?Java ReplyFailure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReplyFailure类属于io.vertx.core.eventbus包,在下文中一共展示了ReplyFailure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
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());
}
}
});
}
示例2: replyJson
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
private static JsonObject replyJson(ReplyException ex) {
JsonObject jsonObject = new JsonObject();
DefaultErrorCode errorCode = DefaultErrorCode.getCode(ex.failureCode());
if (errorCode != null) {
jsonObject.put("code", errorCode.getNumber())
.put("message", errorCode.getMessage());
} else {
ReplyFailure replyFailure = ex.failureType();
if (replyFailure == ReplyFailure.NO_HANDLERS) {
jsonObject.put("code", DefaultErrorCode.SERVICE_UNAVAILABLE.getNumber())
.put("message", DefaultErrorCode.SERVICE_UNAVAILABLE.getMessage());
} else if (replyFailure == ReplyFailure.TIMEOUT) {
jsonObject.put("code", DefaultErrorCode.TIME_OUT.getNumber())
.put("message", DefaultErrorCode.TIME_OUT.getMessage());
} else if (replyFailure == ReplyFailure.RECIPIENT_FAILURE) {
jsonObject.put("code", ex.failureCode())
.put("message", ex.getMessage());
} else {
jsonObject.put("code", DefaultErrorCode.UNKOWN.getNumber())
.put("message", DefaultErrorCode.UNKOWN.getMessage());
}
}
return jsonObject;
}
示例3: failed
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
private void failed(Future<RpcResponse> completed,
Throwable throwable) {
if (throwable instanceof ReplyException) {
ReplyException ex = (ReplyException) throwable;
if (ex.failureType() == ReplyFailure.NO_HANDLERS) {
SystemException resourceNotFoundEx =
SystemException.create(DefaultErrorCode.SERVICE_UNAVAILABLE)
.set("details", "No handlers");
completed.fail(resourceNotFoundEx);
} else {
ErrorCode errorCode = CustomErrorCode.create(ex.failureCode(), ex.getMessage(), 400);
SystemException systemException
= SystemException.create(errorCode);
completed.fail(systemException);
}
} else {
completed.fail(throwable);
}
}
示例4: testCallWithMessageParamWrongType
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testCallWithMessageParamWrongType() {
JsonObject message = new JsonObject();
message.put("object", new JsonObject().put("foo", "bar"));
message.put("str", 76523);
message.put("i", 1234);
message.put("char", (int)'X'); // chars are mapped to ints
message.put("enum", SomeEnum.BAR.toString()); // enums are mapped to strings
vertx.eventBus().send("someaddress", message, new DeliveryOptions().addHeader("action", "invokeWithMessage").setSendTimeout(500), onFailure(t -> {
assertTrue(t instanceof ReplyException);
ReplyException re = (ReplyException) t;
// This will as operation will fail to be invoked
assertEquals(ReplyFailure.RECIPIENT_FAILURE, re.failureType());
testComplete();
}));
await();
}
示例5: replyFailure
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Override
public void replyFailure(String address, ReplyFailure failure) {
switch (failure) {
case TIMEOUT:
counterService.increment("reply.failures.timeout");
break;
case NO_HANDLERS:
counterService.increment("reply.failures.noHandlers");
break;
case RECIPIENT_FAILURE:
counterService.increment("reply.failures.recipientFailure");
break;
}
}
示例6: shutdownHandler
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
/**
* Use to terminate the application using a HTTP Post
* It requires an AdminKey header to work
*/
private void shutdownHandler(final RoutingContext ctx) {
// check for AdminKey header
String adminKey = this.config().getString("AdminKey");
if (adminKey == null || adminKey.equals(ctx.request().getHeader("AdminKey"))) {
// TODO: check the body for the right credentials
this.shutdownExecution(ctx.response());
} else {
ctx.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 401, "Sucker nice try!"));
}
}
示例7: createServer
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Before
public void createServer(TestContext testContext) {
vertx = Vertx.vertx();
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.route().handler(BaseHandler.create());
router.get("/ex/sys").handler(rc -> {
throw SystemException.create(DefaultErrorCode.MISSING_ARGS);
});
router.get("/ex/validate").handler(rc -> {
Multimap<String, String> error = ArrayListMultimap.create();
throw new ValidationException(error);
});
router.get("/ex/unkown").handler(rc -> {
throw new RuntimeException("xxxx");
});
router.get("/ex/reply").handler(rc -> {
throw new ReplyException(ReplyFailure.TIMEOUT, DefaultErrorCode.INVALID_REQ.getNumber(),
DefaultErrorCode.INVALID_REQ.getMessage());
});
router.get("/ex/reply2").handler(rc -> {
throw new ReplyException(ReplyFailure.RECIPIENT_FAILURE);
});
router.route().failureHandler(FailureHandler.create());
vertx.createHttpServer().requestHandler(router::accept)
.listen(port, testContext.asyncAssertSuccess());
}
示例8: consumerSendTimeout
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
public void consumerSendTimeout(@Observes @VertxConsumer(TEST_BUS_TIMEOUT) VertxEvent event) {
assertEquals(TEST_BUS_TIMEOUT, event.getAddress());
event.messageTo(TEST_SLOW_HANDLER).setDeliveryOptions(new DeliveryOptions().setSendTimeout(10)).send("foo", (r) -> {
if (r.failed()) {
ReplyException exception = (ReplyException) r.cause();
if (exception.failureType().equals(ReplyFailure.TIMEOUT)) {
SYNCHRONIZER.add("timeout");
}
}
});
}
示例9: testThrowableToCodeReplyException
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
/**
* Test code of {@link ReplyException}
*/
@Test
public void testThrowableToCodeReplyException() {
int expectedCode = 505;
Throwable throwable = new ReplyException(ReplyFailure.NO_HANDLERS, expectedCode, "Message");
int statusCode = ThrowableHelper.throwableToCode(throwable);
assertEquals(expectedCode, statusCode);
}
示例10: replyFailure
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Override
public void replyFailure(String address, ReplyFailure failure) {
Map<String, String> labels = new HashMap<>();
labels.putAll(defaultLabels);
labels.put(SENSISION_CLASS_EB_LABEL_ADDRESS, address);
incrementMetric(SENSISION_CLASS_EB_MESSAGE_REPLY_ERROR_COUNT, labels);
}
示例11: testEventBusMetricsReplyNoHandlers
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testEventBusMetricsReplyNoHandlers() {
vertx.eventBus().send("foo", "bar", new DeliveryOptions().setSendTimeout(300), ar -> {
assertTrue(ar.failed());
testComplete();
});
await();
JsonObject metrics = metricsService.getMetricsSnapshot(vertx.eventBus());
assertCount(metrics.getJsonObject("messages.reply-failures"), 1L);
assertCount(metrics.getJsonObject("messages.reply-failures." + ReplyFailure.NO_HANDLERS), 1L);
}
示例12: testEventBusMetricsReplyTimeout
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testEventBusMetricsReplyTimeout() {
vertx.eventBus().consumer("foo").handler(msg -> {});
vertx.eventBus().send("foo", "bar", new DeliveryOptions().setSendTimeout(300), ar -> {
assertTrue(ar.failed());
testComplete();
});
await();
JsonObject metrics = metricsService.getMetricsSnapshot(vertx.eventBus());
assertCount(metrics.getJsonObject("messages.reply-failures"), 1L);
assertCount(metrics.getJsonObject("messages.reply-failures." + ReplyFailure.TIMEOUT), 1L);
}
示例13: testEventBusMetricsReplyRecipientFailure
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testEventBusMetricsReplyRecipientFailure() {
vertx.eventBus().consumer("foo").handler(msg -> msg.fail(1, "blah"));
vertx.eventBus().send("foo", "bar", new DeliveryOptions(), ar -> {
assertTrue(ar.failed());
testComplete();
});
await();
JsonObject metrics = metricsService.getMetricsSnapshot(vertx.eventBus());
assertCount(metrics.getJsonObject("messages.reply-failures"), 1L);
assertCount(metrics.getJsonObject("messages.reply-failures." + ReplyFailure.RECIPIENT_FAILURE), 1L);
}
示例14: testFailingMethod
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testFailingMethod() {
proxy.failingMethod(onFailure(t -> {
assertTrue(t instanceof ReplyException);
ReplyException re = (ReplyException) t;
assertEquals(ReplyFailure.RECIPIENT_FAILURE, re.failureType());
assertEquals("wibble", re.getMessage());
testComplete();
}));
await();
}
示例15: testCallWithMessageInvalidAction
import io.vertx.core.eventbus.ReplyFailure; //导入依赖的package包/类
@Test
public void testCallWithMessageInvalidAction() {
JsonObject message = new JsonObject();
message.put("object", new JsonObject().put("foo", "bar"));
message.put("str", "blah");
message.put("i", 1234);
vertx.eventBus().send("someaddress", message, new DeliveryOptions().addHeader("action", "yourmum").setSendTimeout(500), onFailure(t -> {
assertTrue(t instanceof ReplyException);
ReplyException re = (ReplyException) t;
// This will as operation will fail to be invoked
assertEquals(ReplyFailure.RECIPIENT_FAILURE, re.failureType());
testComplete();
}));
await();
}