use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class JSONEventBusTest method testChangesNotVisibleArray2.
@Test
public void testChangesNotVisibleArray2() {
final JsonArray obj = new JsonArray();
eb.<JsonArray>consumer("foo").handler((Message<JsonArray> msg) -> msg.body().add("blah"));
eb.send("foo", obj);
vertx.setTimer(1000, id -> {
assertEquals(0, obj.size());
testComplete();
});
await();
}
use of io.vertx.core.eventbus.Message in project hono by eclipse.
the class EventBusService method processRequestMessage.
private void processRequestMessage(final Message<JsonObject> msg) {
if (log.isTraceEnabled()) {
log.trace("received request message: {}", msg.body().encodePrettily());
}
final EventBusMessage request = EventBusMessage.fromJson(msg.body());
processRequest(request).recover(t -> {
log.debug("cannot process request [operation: {}]: {}", request.getOperation(), t.getMessage());
final int status = Optional.of(t).map(cause -> {
if (cause instanceof ServiceInvocationException) {
return ((ServiceInvocationException) cause).getErrorCode();
} else {
return null;
}
}).orElse(HttpURLConnection.HTTP_INTERNAL_ERROR);
return Future.succeededFuture(request.getResponse(status));
}).map(response -> {
if (response.getReplyToAddress() == null) {
log.debug("sending response as direct reply to request [operation: {}]", request.getOperation());
msg.reply(response.toJson());
} else if (response.hasResponseProperties()) {
log.debug("sending response [operation: {}, reply-to: {}]", request.getOperation(), request.getReplyToAddress());
vertx.eventBus().send(request.getReplyToAddress(), response.toJson());
} else {
log.warn("discarding response lacking correlation ID or operation");
}
return null;
});
}
use of io.vertx.core.eventbus.Message in project vertx-swagger by bobxwang.
the class Application method demo.
/**
* a demo method about how to using vertx
*
* @param applicationContext
*/
private void demo(ApplicationContext applicationContext) {
final Vertx vertx = applicationContext.getBean(Vertx.class);
vertx.setPeriodic(1000, id -> {
// This handler will get called every second
System.out.println("timer fired!" + new Date().toString());
});
vertx.setTimer(1000, id -> {
// this handler will called after one second, just once
System.out.println("And one second later this is printed");
});
// 拦截所有消息
vertx.eventBus().addInterceptor(event -> {
Message message = event.message();
logger.info(message);
event.next();
});
FileResolver fileResolver = new FileResolver(vertx);
File file = fileResolver.resolveFile("webjars/bycdao-ui/cdao/DUI.js");
if (file != null) {
System.out.println(file.getAbsoluteFile());
} else {
System.out.println("null");
}
}
use of io.vertx.core.eventbus.Message in project vertx-zero by silentbalanceyh.
the class AsyncInvoker method next.
@Override
@SuppressWarnings("unchecked")
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
final Envelop envelop = message.body();
// Get type of parameter first element
final Class<?> argType = method.getParameterTypes()[Values.IDX];
// Deserialization from message bus.
final Class<?> returnType = method.getReturnType();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), returnType, true);
// Get T
final Class<?> tCls = returnType.getComponentType();
if (Envelop.class == tCls) {
// Input type is Envelop, input directly
final Future<Envelop> result = Instance.invoke(proxy, method.getName(), envelop);
result.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(item)).setHandler(Ux.toHandler(message));
} else {
final Object reference = envelop.data();
final Object arguments = Ut.deserialize(Ut.toString(reference), argType);
final Future future = Instance.invoke(proxy, method.getName(), arguments);
future.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(Ux.to(item))).compose(item -> Future.succeededFuture(Ux.to(item))).setHandler(Ux.toHandler(message));
}
}
use of io.vertx.core.eventbus.Message in project vertx-zero by silentbalanceyh.
the class SyncInvoker method next.
@Override
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
final Envelop envelop = message.body();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), method.getReturnType(), true);
final Envelop result = Instance.invoke(proxy, method.getName(), envelop);
TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(result).compose(item -> Future.succeededFuture(Ux.to(item))).setHandler(Ux.toHandler(message));
}
Aggregations