我是Camel的新手,我正在尝试设置一个非常简单的应用程序来熟悉它,我正在运行以下代码:
CamelContext cc = (CamelContext)ac.getBean("testCamelContext");
ProducerTemplate template = cc.createProducerTemplate();
System.out.println("Sending Message Body");
template.sendBody("seda:testProducer", "hello");
System.out.println("Sent");
哪个运行正常,但我的消费者似乎从来没有收到消息,我在控制台上得到以下内容:
[ main] SpringCamelContext INFO Apache Camel 2.10.2 (CamelContext: testCamelContext) is starting
[ main] ManagementStrategyFactory INFO JMX enabled.
[ main] DefaultTypeConverter INFO Loaded 172 type converters
[ main] SpringCamelContext INFO Route: route1 started and consuming from: Endpoint[seda://testProducer]
[ main] ultManagementLifecycleStrategy INFO StatisticsLevel at All so enabling load performance statistics
[ main] SpringCamelContext INFO Total 1 routes, of which 1 is started.
[ main] SpringCamelContext INFO Apache Camel 2.10.2 (CamelContext: testCamelContext) started in 0.373 seconds
Init Context
SendingMessage
Sending Message Body
Sent
使用以下驼峰语境:
<camel:camelContext id="testCamelContext">
<camel:routeBuilder ref="testCamelRouteBuilder"/>
</camel:camelContext>
和RouteBuilder规则:
from("seda:testProducer").beanRef("testConsumer","consumeMessage");
以下消费者bean:
public class TestConsumer {
public void consumeMessage(String msg)
{
System.out.println("Message: " + msg);
}
}
所有豆子都很好,骆驼似乎检测到了规则,所以我不确定我做错了什么。我显然没有正确使用东西?
答案 0 :(得分:1)
意识到错误;因为seda是异步的,所以主线程在消费者线程有机会接收消息之前完成。添加了一个thread.sleep(),它运行得很好。