当前位置: 首页>>代码示例>>Java>>正文


Java ProducerTemplate.asyncSendBody方法代码示例

本文整理汇总了Java中org.apache.camel.ProducerTemplate.asyncSendBody方法的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate.asyncSendBody方法的具体用法?Java ProducerTemplate.asyncSendBody怎么用?Java ProducerTemplate.asyncSendBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.ProducerTemplate的用法示例。


在下文中一共展示了ProducerTemplate.asyncSendBody方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWithDirectEndpoint

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testWithDirectEndpoint(TestContext context) throws Exception {
  Async async = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel("direct:foo").toVertx("test")));

  vertx.eventBus().consumer("test", message -> {
    context.assertEquals("hello", message.body());
    async.complete();
  });

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

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, "hello");
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:20,代码来源:InboundEndpointTest.java

示例2: testWithDirectEndpointAndCustomType

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testWithDirectEndpointAndCustomType(TestContext context) throws Exception {
  Async async = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

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

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel("direct:foo").toVertx("test")));

  vertx.eventBus().<Person>consumer("test", message -> {
    context.assertEquals("bob", message.body().getName());
    async.complete();
  });

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

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, new Person().setName("bob"));
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:22,代码来源:InboundEndpointTest.java

示例3: testWithDirectEndpoint2

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testWithDirectEndpoint2(TestContext context) throws Exception {
  Async async = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel(endpoint).toVertx("test")));

  vertx.eventBus().consumer("test", message -> {
    context.assertEquals("hello", message.body());
    async.complete();
  });

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

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, "hello");
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:20,代码来源:InboundEndpointTest.java

示例4: testWithDirectEndpointWithPublish

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testWithDirectEndpointWithPublish(TestContext context) throws Exception {
  Async async = context.async();
  Async async2 = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel(endpoint).toVertx("test").usePublish()));

  vertx.eventBus().consumer("test", message -> {
    context.assertEquals("hello", message.body());
    async.complete();
  });

  vertx.eventBus().consumer("test", message -> {
    context.assertEquals("hello", message.body());
    async2.complete();
  });

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

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, "hello");
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:26,代码来源:InboundEndpointTest.java

示例5: testWithDirectEndpointWithPublishAndCustomType

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testWithDirectEndpointWithPublishAndCustomType(TestContext context) throws Exception {
  Async async = context.async();
  Async async2 = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

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

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel(endpoint).toVertx("test").usePublish()));

  vertx.eventBus().<Person>consumer("test", message -> {
    context.assertEquals("bob", message.body().getName());
    async.complete();
  });

  vertx.eventBus().<Person>consumer("test", message -> {
    context.assertEquals("bob", message.body().getName());
    async2.complete();
  });

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

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, new Person().setName("bob"));
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:28,代码来源:InboundEndpointTest.java

示例6: testMessageProviderRoute

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMessageProviderRoute() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").
            transform(body().prepend("Hello ")).
            to("jms:queue:" + QUEUE_NAME + "?connectionFactory=ConnectionFactory");
        }
    });

    final List<String> result = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(1);

    camelctx.start();
    try {
        // Get the message from the queue
        InitialContext initialctx = new InitialContext();
        ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
        Connection connection = cfactory.createConnection();
        try {
            receiveMessage(connection, QUEUE_JNDI_NAME, new MessageListener() {
                @Override
                public void onMessage(Message message) {
                    TextMessage text = (TextMessage) message;
                    try {
                        result.add(text.getText());
                    } catch (JMSException ex) {
                        result.add(ex.getMessage());
                    }
                    latch.countDown();
                }
            });

            ProducerTemplate producer = camelctx.createProducerTemplate();
            producer.asyncSendBody("direct:start", "Kermit");

            Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
            Assert.assertEquals("One message", 1, result.size());
            Assert.assertEquals("Hello Kermit", result.get(0));
        } finally {
            connection.close();
        }
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-camel,代码行数:50,代码来源:JMSIntegrationTest.java

示例7: testMessageProviderRoute

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMessageProviderRoute() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").
                    transform(body().prepend("Hello ")).
                    to("jms:queue:" + Main.QUEUE_NAME + "?connectionFactory=ConnectionFactory");
        }
    });

    final List<String> result = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(1);

    camelctx.start();
    try {
        // Get the message from the queue
        InitialContext initialctx = new InitialContext();
        ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
        Connection connection = cfactory.createConnection();
        try {
            receiveMessage(connection, Main.QUEUE_JNDI_NAME, new MessageListener() {
                @Override
                public void onMessage(Message message) {
                    TextMessage text = (TextMessage) message;
                    try {
                        result.add(text.getText());
                    } catch (JMSException ex) {
                        result.add(ex.getMessage());
                    }
                    latch.countDown();
                }
            });

            ProducerTemplate producer = camelctx.createProducerTemplate();
            producer.asyncSendBody("direct:start", "Kermit");

            Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
            Assert.assertEquals("One message", 1, result.size());
            Assert.assertEquals("Hello Kermit", result.get(0));
        } finally {
            connection.close();
        }
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:50,代码来源:JMSIntegrationTest.java


注:本文中的org.apache.camel.ProducerTemplate.asyncSendBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。