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());
}
use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class DeploymentTest method testIsolationGroup.
// TODO
// Multi-threaded workers
private void testIsolationGroup(String group1, String group2, int count1, int count2, List<String> isolatedClasses, String verticleID) throws Exception {
Map<String, Integer> countMap = new ConcurrentHashMap<>();
vertx.eventBus().<JsonObject>consumer("testcounts").handler((Message<JsonObject> msg) -> {
countMap.put(msg.body().getString("deploymentID"), msg.body().getInteger("count"));
});
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<String> deploymentID1 = new AtomicReference<>();
AtomicReference<String> deploymentID2 = new AtomicReference<>();
vertx.deployVerticle(verticleID, new DeploymentOptions().setIsolationGroup(group1).setIsolatedClasses(isolatedClasses), ar -> {
assertTrue(ar.succeeded());
deploymentID1.set(ar.result());
assertEquals(0, TestVerticle.instanceCount.get());
vertx.deployVerticle(verticleID, new DeploymentOptions().setIsolationGroup(group2).setIsolatedClasses(isolatedClasses), ar2 -> {
assertTrue(ar2.succeeded());
deploymentID2.set(ar2.result());
assertEquals(0, TestVerticle.instanceCount.get());
latch.countDown();
});
});
awaitLatch(latch);
// Wait until two entries in the map
waitUntil(() -> countMap.size() == 2);
assertEquals(count1, countMap.get(deploymentID1.get()).intValue());
assertEquals(count2, countMap.get(deploymentID2.get()).intValue());
}
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();
}
use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class JSONEventBusTest method testChangesNotVisibleObject1.
@Test
public void testChangesNotVisibleObject1() {
JsonObject obj = new JsonObject();
eb.<JsonObject>consumer("foo").handler((Message<JsonObject> msg) -> {
assertFalse(msg.body().containsKey("b"));
testComplete();
});
eb.send("foo", obj);
obj.put("b", "blurrgg");
await();
}
use of io.vertx.core.eventbus.Message in project vertx-examples by vert-x3.
the class Combine method start.
@Suspendable
@Override
public void start() 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
vertx.setPeriodic(500, tid -> {
eb.send(ADDRESS1, "wibble");
eb.send(ADDRESS2, "flibble");
});
ReceivePort<Message<String>> channel1 = adaptor1.receivePort();
ReceivePort<Message<String>> channel2 = adaptor2.receivePort();
// Combine them into a single channel
// Not sure how to avoid this ugly cast with Quasar
Mix<Message<String>> mix = (Mix<Message<String>>) Channels.mix(channel1, channel2);
// Take the first ten
for (int i = 0; i < 10; i++) {
Message<String> msg = mix.receive();
System.out.println("got message: " + msg.body());
}
System.out.println("done");
}
Aggregations