本文整理汇总了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();
}
}