apache-camel - Camel 不断发送消息

标签 apache-camel rabbitmq

我正在使用 Camel 进行集成。我有一个用例,其中 Camel 应该将 1 条消息从一个队列传输到另一个队列,但它不断向队列发送相同的消息。请查看我的以下路线:

ProducerTemplate正在按以下方式创建消息:

ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct://input", "This is a test message: ");

我有一条路由将消息从直接组件传输到 rabbitmq 队列。

public void configure() throws Exception {
                from("direct://input")
                .to("rabbitmq://localhost:5672/test_ip?queue=task_queue&routingKey=test_task" +
                                "&autoAck=true&durable=true&username=guest&password=guest&autoDelete=false&exchangePattern=InOut")

            }

然后我有一个路由将消息从 task_queue 传输到 out_queue

 public void configure() throws Exception {
                from("rabbitmq://localhost:5672/test_ip?queue=task_queue&username=guest&routingKey=test_task&password=guest" +
                        "&autoAck=true&durable=true&exchangeType=direct&autoDelete=false&exchangePattern=InOut")
        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                exchange.setOut(exchange.getIn());
                                Message m = exchange.getOut();
                                org.apache.camel.TypeConverter tc = exchange.getContext().getTypeConverter();
                                String strValue = tc.convertTo(String.class, m.getBody());
                                System.out.println("[[task_queue -- out_queue]]: "  + strValue);
                            }
                        })
                       .to("rabbitmq://localhost:5672/test_op?queue=out_queue&routingKey=test_out&username=guest&password=guest" +
                            "&autoAck=true&durable=true&exchangeType=direct&autoDelete=false&exchangePattern=InOut");
            }

我的程序中只有这两条路线,没有别的。现在,当我运行它时,我得到以下输出:

[[task_queue -- out_queue]]: This is a test message: 
[[task_queue -- out_queue]]: This is a test message: 
[[task_queue -- out_queue]]: This is a test message: 
[[task_queue -- out_queue]]: This is a test message: 
[[task_queue -- out_queue]]: This is a test message: 
.
.
(continuous stream till I kill program)

我上面显示的输出不是预期的输出。它不应该多次打印 out 消息,而应该只打印一次。这意味着 1 条消息被一次又一次地处理(并传输到 out_queue)。

谁能给出原因?感谢您的帮助。

最佳答案

关于apache-camel - Camel 不断发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25260126/

相关文章:

java - Apache Camel 内存死信队列

java - 如何调用Camel读取文件的路由?

java - 如何在RabbitMq上进行 "topic-like"消费?

ruby-on-rails - neo4j 与 "traditional"RDBMS 和 Memcached/消息传递/Redis 解决方案

docker - Docker 中 RabbitMQ 的端口转发失败

ubuntu - 由于不满足依赖关系而无法安装rabbitmq : libssl

python - Celery 第一步 - result.get() 超时错误

Apache Camel MDC 从 Body 添加字段

apache-kafka - 无法使用kafka中的旧消息

java - Apache Camel 脚本问题