我试图让Camel RabbitMQ集成工作,只是将队列消息打印到控制台。
使用RabbitMQ Web界面,当我启动camel实例时,我可以看到连接。
我创建了一个名为" test"的直接交换。和一个名为" test"并将它们绑在一起。
然后我使用RabbitMQ Web界面向交易所发布消息。
这是我使用的骆驼代码,但我没有看到任何东西出现在我的控制台上,而且我没有在骆驼方面看到任何消息接收确认。骆驼也没有展示任何消费者的消费者。连接的。
public class IntegrationRouteFromRabbitMQBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
System.out.println("IntegrationRouteFromRabbitMQBuilder Instantiated");
from("rabbitmq://localhost/test?queue=test").to("stream:out");
}
}
我做了一件明显错误的事吗?或者还有什么我可以尝试将其连接起来吗?我尝试过添加路由密钥,但没有运气。
由于
更新要进行此设置,我使用了以下模式:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html这是独立的启动器......
我唯一能做的就是main.addRouteBuilder(new IntegrationRouteFromRabbitMQBuilder());根据我的理解,应该设置上下文并解雇所有内容。
public void boot() throws Exception {
// create a Main instance
main = new Main();
// enable hangup support so you can press ctrl + c to terminate the JVM
main.enableHangupSupport();
// add routes
main.addRouteBuilder(new IntegrationRouteFromRabbitMQBuilder());
// run until you terminate the JVM
System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
main.run();
}
更新2
添加错误日志输出
17:05:09.886 [main] INFO o.a.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: Endpoint[rabbitmq://localhost/test?exchangeType=fanout&queue=test&routingKey=test123]
17:05:09.886 [Camel (camel-1) thread #1 - RabbitMQConsumer] TRACE o.a.c.c.rabbitmq.RabbitMQConsumer - Creating connection...
17:05:09.886 [main] TRACE o.a.camel.support.ServiceSupport - Starting service
17:05:09.886 [main] TRACE org.apache.camel.util.EventHelper - Notification of event is disabled: Started route: route1
17:05:09.886 [main] DEBUG o.a.c.m.DefaultManagementLifecycleStrategy - Load performance statistics disabled
17:05:09.886 [main] INFO o.a.camel.impl.DefaultCamelContext - Total 1 routes, of which 1 is started.
17:05:09.887 [main] INFO o.a.camel.impl.DefaultCamelContext - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.573 seconds
17:05:09.888 [main] TRACE org.apache.camel.util.EventHelper - Notification of event is disabled: Started CamelContext: camel-1
17:05:09.889 [Camel (camel-1) thread #1 - RabbitMQConsumer] DEBUG o.a.c.c.rabbitmq.RabbitMQConsumer - Created connection: amqp://guest@127.0.0.1:5672/
17:05:09.889 [Camel (camel-1) thread #1 - RabbitMQConsumer] TRACE o.a.c.c.rabbitmq.RabbitMQConsumer - Creating channel...
17:05:09.889 [Camel (camel-1) thread #1 - RabbitMQConsumer] DEBUG o.a.c.c.rabbitmq.RabbitMQConsumer - Created channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1)
17:05:09.890 [pool-3-thread-3] TRACE o.a.c.u.c.CamelThreadFactory - Created thread[Camel (camel-1) thread #2 - RabbitMQConsumer] -> Thread[Camel (camel-1) thread #2 - RabbitMQConsumer,5,main]
答案 0 :(得分:0)
我能够通过不使用RabbitMQ接口发布消息来解决这个问题。
我使用RabbitMQ教程中的Send.java应用程序发布消息,以确保我们能够确保所有队列和交换正确,并且它有效。