本文整理匯總了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");
}
示例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"));
}
示例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");
}
示例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");
}
示例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"));
}
示例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();
}
}
示例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();
}
}