Java Code Examples for org.apache.camel.ProducerTemplate#asyncRequestBody()

The following examples show how to use org.apache.camel.ProducerTemplate#asyncRequestBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InboundReplyTest.java    From vertx-camel-bridge with Apache License 2.0 6 votes vote down vote up
@Test
public void testReply() throws Exception {
  Endpoint endpoint = camel.getEndpoint("direct:stuff");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(new InboundMapping().setAddress("test-reply").setEndpoint(endpoint)));

  vertx.eventBus().consumer("test-reply", message -> {
    message.reply("How are you ?");
  });

  camel.start();
  BridgeHelper.startBlocking(bridge);

  ProducerTemplate template = camel.createProducerTemplate();
  Future<Object> future = template.asyncRequestBody(endpoint, "hello");
  String response = template.extractFutureBody(future, String.class);
  assertThat(response).isEqualTo("How are you ?");
}
 
Example 2
Source File: InboundReplyTest.java    From vertx-camel-bridge with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplyWithCustomType() throws Exception {
  Endpoint endpoint = camel.getEndpoint("direct:stuff");

  vertx.eventBus().registerDefaultCodec(Person.class, new PersonCodec());

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(new InboundMapping().setAddress("test-reply").setEndpoint(endpoint)));

  vertx.eventBus().consumer("test-reply", message -> {
    message.reply(new Person().setName("alice"));
  });

  camel.start();
  BridgeHelper.startBlocking(bridge);

  ProducerTemplate template = camel.createProducerTemplate();
  Future<Object> future = template.asyncRequestBody(endpoint, new Person().setName("bob"));
  Person response = template.extractFutureBody(future, Person.class);
  assertThat(response.getName()).isEqualTo("alice");
}