io.vertx.core.eventbus.Message.body()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中io.vertx.core.eventbus.Message.body()方法的一些代码示例,展示了Message.body()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.body()方法的具体详情如下:
包路径:io.vertx.core.eventbus.Message
类名称:Message
方法名:body

Message.body介绍

[英]The body of the message. Can be null.
[中]信息的主体。可以为空。

代码示例

代码示例来源:origin: vert-x3/vertx-examples

@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!");
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testPauseFetchMessageStream() throws Exception {
 testPauseFetch((consumer, handler) -> consumer.handler(message -> handler.handle(message.body())));
}

代码示例来源:origin: eclipse-vertx/vert.x

@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();
}

代码示例来源:origin: eclipse-vertx/vert.x

@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();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testExceptionWhenDeliveringBufferedMessageWithMessageStream() {
 testExceptionWhenDeliveringBufferedMessage((consumer, handler) -> consumer.handler(message -> handler.handle(message.body())));
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {
  vertx.eventBus().consumer("news", message -> {
   System.out.println(">> " + message.body());
  });
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testSender() {
 String str = TestUtils.randomUnicodeString(100);
 WriteStream<String> sender = eb.sender(ADDRESS1);
 eb.consumer(ADDRESS1).handler(message -> {
  if (message.body().equals(str)) {
   testComplete();
  }
 });
 sender.write(str);
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testPauseResumeMessageStream() {
 testPauseResume((consumer, handler) -> consumer.handler(message -> handler.handle(message.body())));
}

代码示例来源:origin: vert-x3/vertx-examples

@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());
  });
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
 public void testChangesNotVisibleArray3() {
  List<Object> list = new ArrayList<>();
  final JsonArray obj = new JsonArray(list);
  eb.<JsonArray>consumer("foo").handler((Message<JsonArray> msg) -> {
   vertx.setTimer(1000, id -> {
    assertEquals(0, msg.body().size());
    testComplete();
   });
  });
  eb.send("foo", obj);
  list.add("uhwqdiuh");
  await();
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testRegisterLocal2() {
 String str = TestUtils.randomUnicodeString(100);
 eb.localConsumer(ADDRESS1, (Message<String> msg) -> {
  assertEquals(str, msg.body());
  testComplete();
 }).completionHandler(ar -> {
  assertTrue(ar.succeeded());
  eb.send(ADDRESS1, str);
 });
 await();
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  EventBus eb = vertx.eventBus();

  eb.consumer("ping-address", message -> {

   System.out.println("Received message: " + message.body());
   // Now send back reply
   message.reply("pong!");
  });

  System.out.println("Receiver ready!");
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testPublishSameHandlerRegisteredTwice() {
 String str = TestUtils.randomUnicodeString(1000);
 AtomicInteger count = new AtomicInteger();
 Handler<Message<String>> handler = (Message<String> msg) -> {
  assertEquals(str, msg.body());
  if (count.incrementAndGet() == 2) {
   testComplete();
  }
 };
 eb.<String>consumer(ADDRESS1).handler(handler);
 eb.<String>consumer(ADDRESS1).handler(handler);
 eb.publish(ADDRESS1, str);
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testRegisterLocal1() {
 String str = TestUtils.randomUnicodeString(100);
 eb.<String>localConsumer(ADDRESS1).handler((Message<String> msg) -> {
  assertEquals(str, msg.body());
  testComplete();
 }).completionHandler(ar -> {
  assertTrue(ar.succeeded());
  eb.send(ADDRESS1, str);
 });
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

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;
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testPublishMultipleHandlers() {
 String str = TestUtils.randomUnicodeString(100);
 AtomicInteger count = new AtomicInteger();
 eb.<String>consumer(ADDRESS1).handler((Message<String> msg) -> {
  assertEquals(str, msg.body());
  if (count.incrementAndGet() == 2) {
   testComplete();
  }
 });
 eb.<String>consumer(ADDRESS1).handler((Message<String> msg) -> {
  assertEquals(str, msg.body());
  if (count.incrementAndGet() == 2) {
   testComplete();
  }
 });
 eb.publish(ADDRESS1, str);
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testReplyFromWorker() throws Exception {
 String expectedBody = TestUtils.randomAlphaString(20);
 startNodes(2);
 CountDownLatch latch = new CountDownLatch(1);
 vertices[0].deployVerticle(new AbstractVerticle() {
  @Override
  public void start() throws Exception {
   vertices[1].eventBus().<String>consumer(ADDRESS1, msg -> {
    msg.reply(expectedBody);
   }).completionHandler(ar -> {
    assertTrue(ar.succeeded());
    latch.countDown();
   });
  }
 }, new DeploymentOptions().setWorker(true));
 awaitLatch(latch);
 vertices[0].eventBus().send(ADDRESS1, "whatever", reply -> {
  assertTrue(reply.succeeded());
  assertEquals(expectedBody, reply.result().body());
  testComplete();
 });
 await();
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  EventBus eb = vertx.eventBus();

  eb.consumer("ping-address", message -> {

   System.out.println("Received message: " + message.body());
   // Now send back reply
   message.reply("pong!");
  });

  System.out.println("Receiver ready!");
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@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);
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() {
  vertx.eventBus().<String>consumer("request", message -> message.reply("hello " + message.body()));

  vertx.createHttpServer()
    .requestHandler(request -> request.response().end("OK"))
    .listen(8080);
 }
}

相关文章