在本指南
https://www.rabbitmq.com/api-guide.html RabbitMQ家伙状态:
Channels and Concurrency Considerations (Thread Safety)
Channel instances must not be shared between threads. Applications should prefer using a Channel per thread instead of sharing the same Channel across multiple threads. While some operations on channels are safe to invoke concurrently, some are not and will result in incorrect frame interleaving on the wire. Sharing channels between threads will also interfere with * Publisher Confirms.
线程安全性非常重要,所以我尽可能的努力,但这里的问题是:
我有这个应用程序接收来自Rabbit的消息.收到消息时,它会处理它,然后在完成消息时进行确认.该应用程序可以在具有2个线程的固定线程池中同时处理两个项目. ROS的QOS预取设置为2,因为我不想在一个时间框架内处理更多的应用程序.
现在,我的消费者的handleDelivery执行以下操作:
Task run = new Task(JSON.parse(message));
service.execute(new TestWrapperThread(getChannel(),run,envelope.getDeliveryTag()));
在这一点上,你已经知道TestWrapperThread做了channel.basicAck(deliveryTag,false);称为最后一次操作.
通过我对文档的理解,这是不正确的,可能是有害的,因为通道不是线程安全的,这种行为可能会使事情发生.但是我应该怎么做呢?我的意思是,我有一些想法,但他们会使一切变得更加复杂,如果真的有必要,我想弄清楚.
提前致谢