use of io.vertx.core.eventbus.Message in project vertx-sync by vert-x3.
the class TestVerticle method testHandlerAdaptor.
@Suspendable
protected void testHandlerAdaptor() throws Exception {
EventBus eb = vertx.eventBus();
// Create a couple of consumers on different addresses
// The adaptor allows handler to be used as a Channel
HandlerReceiverAdaptor<Message<String>> adaptor1 = streamAdaptor();
eb.<String>consumer(ADDRESS1).handler(adaptor1);
HandlerReceiverAdaptor<Message<String>> adaptor2 = streamAdaptor();
eb.<String>consumer(ADDRESS2).handler(adaptor2);
// Set up a periodic timer to send messages to these addresses
long start = System.currentTimeMillis();
vertx.setPeriodic(10, tid -> {
eb.send(ADDRESS1, "wibble");
eb.send(ADDRESS2, "flibble");
});
for (int i = 0; i < 10; i++) {
Message<String> received1 = adaptor1.receive();
assertEquals("wibble", received1.body());
Message<String> received2 = adaptor2.receive();
assertEquals("flibble", received2.body());
}
long end = System.currentTimeMillis();
assertTrue(end - start >= 100);
// Try a receive with timeout
Message<String> received1 = adaptor1.receive(1000);
assertEquals("wibble", received1.body());
// And timing out
HandlerReceiverAdaptor<Message<String>> adaptor3 = streamAdaptor();
eb.<String>consumer(ADDRESS3).handler(adaptor3);
Message<String> received3 = adaptor3.receive(100);
assertNull(received3);
// Try underlying receivePort
ReceivePort<Message<String>> channel = adaptor1.receivePort();
assertNotNull(channel);
received1 = channel.receive();
assertEquals("wibble", received1.body());
complete();
}
use of io.vertx.core.eventbus.Message in project vertx-zero by silentbalanceyh.
the class FutureInvoker method next.
@Override
@SuppressWarnings("unchecked")
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
// Invoke directly
final Envelop envelop = message.body();
// Future<T>
final Class<?> returnType = method.getReturnType();
// Get T
final Class<?> tCls = returnType.getComponentType();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), returnType, true);
if (Envelop.class == tCls) {
// Execute Future<Envelop>
final Future<Envelop> future = Instance.invoke(proxy, method.getName(), envelop);
future.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(item)).setHandler(Ux.toHandler(message));
} else {
final Future future = Instance.invoke(proxy, method.getName(), envelop);
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 DynamicInvoker 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 returnValue = this.executeMethod(proxy, method, envelop);
TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(returnValue).compose(item -> Future.succeededFuture(Ux.to(item))).setHandler(Ux.toHandler(message));
}
use of io.vertx.core.eventbus.Message in project narayana by jbosstm.
the class ModuleIntegrationTest method testPing.
@Test
public // public void testPing(TestContext context) {
void testPing() {
TestContext context = null;
System.out.printf("in testPing()%n");
logger.info("in testPing()");
EventBus eb = vertx.eventBus();
eb.publish("ping-address", "ping!");
eb.consumer("ping-address", (Message<JsonObject> reply) -> {
context.assertEquals("pong! 12", reply.body());
/*
If we get here, the test is complete
You must always call `testComplete()` at the end. Remember that testing is *asynchronous* so
we cannot assume the test is complete by the time the test method has finished executing like
in standard synchronous tests
*/
testComplete();
});
}
use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class JsonEventBusTest method testChangesNotVisibleObject3.
@Test
public void testChangesNotVisibleObject3() {
Map<String, Object> map = new HashMap<>();
final JsonObject obj = new JsonObject(map);
eb.<JsonObject>consumer("foo").handler((Message<JsonObject> msg) -> {
vertx.setTimer(1000, id -> {
assertFalse(msg.body().containsKey("b"));
testComplete();
});
});
eb.send("foo", obj);
map.put("b", "uhqdihuqwd");
await();
}
Aggregations