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();
}));
}
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 VX-API-Gateway by EliMirren.
the class VxApiApplication method addRoute.
/**
* 添加一个路由
*
* @param msg
*/
public void addRoute(Message<JsonObject> msg) {
JsonObject body = msg.body().getJsonObject("api");
VxApisDTO dto = VxApisDTO.fromJson(body);
if (dto != null) {
VxApis api = new VxApis(dto);
// 是否代理启动API到当前应用
boolean otherRouteAdd = msg.body().getBoolean("elseRouteToThis", false);
if (otherRouteAdd) {
// 服务器的类型1=http,2=https,3=webSocket
int type = msg.body().getInteger("serverType", 0);
if (type == 1) {
addHttpRouter(api, res -> {
if (res.succeeded()) {
msg.reply(1);
} else {
msg.fail(500, res.cause().getMessage());
}
});
} else if (type == 2) {
addHttpsRouter(api, res -> {
if (res.succeeded()) {
msg.reply(1);
} else {
msg.fail(500, res.cause().getMessage());
res.cause().printStackTrace();
}
});
} else {
msg.fail(500, "不存在的服务");
}
} else {
// 本应用添加API,既属于自己的网关应用添加API
if (httpRouter != null && httpsRouter != null) {
Future<Boolean> httpFuture = Future.future(http -> addHttpRouter(api, http));
Future<Boolean> httpsFuture = Future.<Boolean>future(https -> addHttpsRouter(api, https));
CompositeFuture.all(httpFuture, httpsFuture).setHandler(res -> {
if (res.succeeded()) {
msg.reply(1);
} else {
msg.fail(500, res.cause().getMessage());
}
});
} else if (httpRouter != null) {
addHttpRouter(api, res -> {
if (res.succeeded()) {
msg.reply(1);
} else {
msg.fail(500, res.cause().getMessage());
}
});
} else if (httpsRouter != null) {
addHttpsRouter(api, res -> {
if (res.succeeded()) {
msg.reply(1);
} else {
msg.fail(500, res.cause().getMessage());
}
});
} else {
msg.fail(404, "找不到的服务器可以加载API");
}
}
} else {
msg.fail(1400, "API参数不能为null,请检查APIDTO需要实例化的JSON编写是否正确");
}
}
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 vert.x by eclipse.
the class NetTest method setHandlers.
void setHandlers(NetSocket sock) {
Handler<Message<Buffer>> resumeHandler = m -> sock.resume();
MessageConsumer reg = vertx.eventBus().<Buffer>consumer("client_resume").handler(resumeHandler);
sock.closeHandler(v -> reg.unregister());
}
Aggregations