當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。