Refine search
@Test public void testContextsPublish() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); int numHandlers = 10; for (int i = 0; i < numHandlers; i++) { vertx.eventBus().consumer(ADDRESS1).handler(msg -> { contexts.add(((VertxInternal) vertx).getContext()); if (cnt.incrementAndGet() == numHandlers) { assertEquals(numHandlers, contexts.size()); testComplete(); } }); } vertx.eventBus().publish(ADDRESS1, "foo"); await(); }
@Test public void testDefaultCodecReplyExceptionSubclass() throws Exception { startNodes(2); MyReplyException myReplyException = new MyReplyException(23, "my exception"); MyReplyExceptionMessageCodec codec = new MyReplyExceptionMessageCodec(); vertices[0].eventBus().registerDefaultCodec(MyReplyException.class, codec); vertices[1].eventBus().registerDefaultCodec(MyReplyException.class, codec); MessageConsumer<ReplyException> reg = vertices[0].eventBus().<ReplyException>consumer(ADDRESS1, msg -> { assertTrue(msg.body() instanceof MyReplyException); testComplete(); }); reg.completionHandler(ar -> { vertices[1].eventBus().send(ADDRESS1, myReplyException); }); await(); }
@Override public void start() throws Exception { System.out.println("[Worker] Starting in " + Thread.currentThread().getName()); vertx.eventBus().<String>consumer("sample.data", message -> { System.out.println("[Worker] Consuming data in " + Thread.currentThread().getName()); String body = message.body(); message.reply(body.toUpperCase()); }); } }
@Test public void testDefaultCodecReplyExceptionSubclass() throws Exception { MyReplyException myReplyException = new MyReplyException(23, "my exception"); vertx.eventBus().registerDefaultCodec(MyReplyException.class, new MyReplyExceptionMessageCodec()); eb.<ReplyException>consumer(ADDRESS1, msg -> { assertTrue(msg.body() instanceof MyReplyException); testComplete(); }); vertx.eventBus().send(ADDRESS1, myReplyException); await(); }
@Test public void testUnregisterDefaultDecoder() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerDefaultCodec(MyPOJO.class, codec); vertx.eventBus().unregisterDefaultCodec(MyPOJO.class); assertIllegalArgumentException(() -> vertx.eventBus().send(ADDRESS1, new MyPOJO("foo"))); }
@Test public void testContextsSend() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); CountDownLatch latch = new CountDownLatch(2); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { msg.reply("bar"); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); }); vertx.eventBus().send(ADDRESS1, "foo", onSuccess((Message<Object> reply) -> { assertEquals("bar", reply.body()); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); })); awaitLatch(latch); assertEquals(2, contexts.size()); }
@Test public void testRegisterRemote2() { startNodes(2); String str = TestUtils.randomUnicodeString(100); vertices[0].eventBus().consumer(ADDRESS1, (Message<String> msg) -> { assertEquals(str, msg.body()); testComplete(); }).completionHandler(ar -> { assertTrue(ar.succeeded()); vertices[1].eventBus().send(ADDRESS1, str); }); await(); }
public MessageProducerImpl(Vertx vertx, String address, boolean send, DeliveryOptions options) { this.vertx = vertx; this.bus = vertx.eventBus(); this.address = address; this.send = send; this.options = options; if (send) { String creditAddress = UUID.randomUUID().toString() + "-credit"; creditConsumer = bus.consumer(creditAddress, msg -> { doReceiveCredit(msg.body()); }); options.addHeader(CREDIT_ADDRESS_HEADER_NAME, creditAddress); } else { creditConsumer = null; } }
@Test public void testGetInstanceCountMultipleVerticles() throws Exception { AtomicInteger messageCount = new AtomicInteger(0); AtomicInteger totalReportedInstances = new AtomicInteger(0); vertx.eventBus().consumer("instanceCount", event -> { messageCount.incrementAndGet(); totalReportedInstances.addAndGet((int)event.body()); if(messageCount.intValue() == 3) { assertEquals(9, totalReportedInstances.get()); testComplete(); } }); vertx.deployVerticle(TestVerticle3.class.getCanonicalName(), new DeploymentOptions().setInstances(3), ar -> { assertTrue(ar.succeeded()); }); await(); Deployment deployment = ((VertxInternal) vertx).getDeployment(vertx.deploymentIDs().iterator().next()); CountDownLatch latch = new CountDownLatch(1); vertx.undeploy(deployment.deploymentID(), ar -> latch.countDown()); awaitLatch(latch); }
@Override public void start() throws Exception { EventBus eb = vertx.eventBus(); eb.consumer("news-feed", message -> System.out.println("Received news on consumer 1: " + message.body())); eb.consumer("news-feed", message -> System.out.println("Received news on consumer 2: " + message.body())); eb.consumer("news-feed", message -> System.out.println("Received news on consumer 3: " + message.body())); System.out.println("Ready!"); } }
@Test public void testClusteredPong() throws Exception { startNodes(2, new VertxOptions().setClusterPingInterval(500).setClusterPingReplyInterval(500)); AtomicBoolean sending = new AtomicBoolean(); MessageConsumer<String> consumer = vertices[0].eventBus().<String>consumer("foobar").handler(msg -> { if (!sending.get()) { sending.set(true); vertx.setTimer(4000, id -> { vertices[1].eventBus().send("foobar", "whatever2"); }); } else { testComplete(); } }); consumer.completionHandler(ar -> { assertTrue(ar.succeeded()); vertices[1].eventBus().send("foobar", "whatever"); }); await(); }