简体   繁体   English

从Java中的不同线程确认rabbitMq消息

[英]Acknowledging rabbitMq messages from different threads in Java

I have a multi- tiered worker pattern implementation using rabbit to distribute the task, so messages come in via one of many "listners"( a executor service with many threads calling consumer.basicConsume(), each with its own Channel). 我有一个使用rabbit来分发任务的多层工作模式实现,因此消息通过许多“列表器”之一(一个执行器服务,其中许多线程调用consumer.basicConsume(),每个都有自己的Channel)。 The messages get passed around the application and then at the final stage they are picked up by an ack listener(again, running out of its own ExecutorService with its own different channels) to be acknowledged, however the acks are not picked up by the server. 消息在应用程序周围传递,然后在最后阶段由ack侦听器(再次,用自己的ExecutorService运行,具有自己的不同通道)接收它们以进行确认,但是服务器不会获取ack 。 I have written a simple test where I acknowledge the message from a different channel in the same thread and in a different thread, on the same thread they work, on a different one they do not, and the same channel on different threads works as well. 我写了一个简单的测试,我在同一个线程和不同的线程中,在他们工作的同一个线程上的不同通道中确认消息,在不同的线程上它们没有,并且不同线程上的相同通道也起作用。

Has anyone come across this before? 有没有人遇到过这个? I really don't want to have to keep a mapping of channels to ids. 我真的不想要保持频道到ID的映射。

It's not recommended at all to ack a message in a different thread, you should avoid this behavior. 根本不建议在不同的线程中激活消息,您应该避免这种行为。 Here it is what the doc says: http://www.rabbitmq.com/api-guide.html#channel-threads 这是文档所说的内容: http//www.rabbitmq.com/api-guide.html#channel-threads

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM