如何为同一Camel RouteBuilder配置方法设置两个RabbitMQ连接 [英] How to set two RabbitMQ connections for the same Camel RouteBuilder configure method
问题描述
我想从兔子队列监听,处理并将消息发布到另一个兔子队列.我不和春天打交道.邮件在此配置中重复.
I want listen FROM rabbit queue, process, and post message TO another rabbit queue. I'm not working with spring. The messages are duplicated in this configuration.
这是一个简短的代码:
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("rabbitmq://localhost/B?autoDelete=false&queue=worker&threadPoolSize=1&autoAck=false").
log(LoggingLevel.INFO, "Message ${id}").
to("rabbitmq://localhost/B?autoDelete=false&queue=processed");
}
});
我也尝试过:
public static void main(String[] args) throws Exception {
org.apache.camel.impl.DefaultCamelContext context = new DefaultCamelContext();
com.rabbitmq.client.ConnectionFactory connectionFactoryWorker = new ConnectionFactory();
com.rabbitmq.client.ConnectionFactory connectionFactoryProcessed = new ConnectionFactory();
org.apache.camel.impl.SimpleRegistry registry = new SimpleRegistry();
String camelBeanNameWorker = "connectionFactoryWorker";
String camelBeanNameProcessed = "connectionFactoryProcessed";
registry.put(camelBeanNameWorker, connectionFactoryWorker);
registry.put(camelBeanNameProcessed, connectionFactoryProcessed);
context.setRegistry(registry);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("rabbitmq://localhost/B?connectionFactory=connectionFactoryWorker&autoDelete=false&queue=worker&threadPoolSize=1&autoAck=false").
log(LoggingLevel.INFO, "Message ${id}").
to("rabbitmq://localhost/B?connectionFactory=connectionFactoryProcessed&autoDelete=false&queue=processed");
}
});
context.start();
Thread.sleep(10000l);
context.stop();
}
工人队列从四个消息开始,但是消息被重新排队:
Worker queue start in four messages, but Messages are re-queued:
561消息ID-host-1510600494291-0-2
566消息ID-host-1510600494291-0-4
566消息ID-host-1510600494291-0-6
567消息ID-host-1510600494291-0-8
568消息ID-host-1510600494291-0-10
571消息ID-host-1510600494291-0-12
572消息ID-host-1510600494291-0-14
572消息ID-host-1510600494291-0-16
573消息ID-host-1510600494291-0-18
574消息ID-host-1510600494291-0-20
574消息ID-host-1510600494291-0-22
575消息ID-host-1510600494291-0-24
576消息ID-host-1510600494291-0-26
576消息ID-host-1510600494291-0-28
577消息ID-host-1510600494291-0-30
578消息ID-host-1510600494291-0-32
578消息ID-host-1510600494291-0-34
...
之后为64k ...
10561邮件ID-host-1510600494291-0-128690
10561邮件ID-host-1510600494291-0-128692
10561邮件ID-host-1510600494291-0-128694
10561邮件ID-host-1510600494291-0-128696
561 Message ID-host-1510600494291-0-2
566 Message ID-host-1510600494291-0-4
566 Message ID-host-1510600494291-0-6
567 Message ID-host-1510600494291-0-8
568 Message ID-host-1510600494291-0-10
571 Message ID-host-1510600494291-0-12
572 Message ID-host-1510600494291-0-14
572 Message ID-host-1510600494291-0-16
573 Message ID-host-1510600494291-0-18
574 Message ID-host-1510600494291-0-20
574 Message ID-host-1510600494291-0-22
575 Message ID-host-1510600494291-0-24
576 Message ID-host-1510600494291-0-26
576 Message ID-host-1510600494291-0-28
577 Message ID-host-1510600494291-0-30
578 Message ID-host-1510600494291-0-32
578 Message ID-host-1510600494291-0-34
...
64k after
...
10561 Message ID-host-1510600494291-0-128690
10561 Message ID-host-1510600494291-0-128692
10561 Message ID-host-1510600494291-0-128694
10561 Message ID-host-1510600494291-0-128696
推荐答案
我相信我可能在另一个问题中找到了您的答案
I believe I may have found your answer in another question
显然,设置BridgeEnpoint = false选项将停止此操作.如果未指定此内容,则从接收到的消息中获取EXCHANGE_NAME和ROUTING_KEY标头,以覆盖您可能在至"配置中指定的内容.例如...
rabbitmq://localhost/B?connectionFactory=connectionFactoryProcessed&autoDelete=false&queue=processed&BridgeEndpoint=false
Apparently setting BridgeEnpoint=false option stops this. Without specifying this the EXCHANGE_NAME and ROUTING_KEY headers are taken from the received message overriding whatever you might have specified in the "to" configuration. For example...
rabbitmq://localhost/B?connectionFactory=connectionFactoryProcessed&autoDelete=false&queue=processed&BridgeEndpoint=false
这篇关于如何为同一Camel RouteBuilder配置方法设置两个RabbitMQ连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!