简体   繁体   English

使用 Spring AMQP 监听许多短暂的、动态创建的队列

[英]Listening to many short-lived, dynamically created queues with Spring AMQP

I'm building an application using RabbitMQ/Spring/Spring AMQP and am having trouble handling the way I've laid out my queues.我正在使用 RabbitMQ/Spring/Spring AMQP 构建一个应用程序,并且在处理我布置队列的方式时遇到了问题。

Essentially I have one queue that every consumer listens to, with each message basically saying "this queue is ready to be processed by a single consumer".本质上,我有一个每个消费者都听的队列,每条消息基本上都在说“这个队列已准备好由单个消费者处理”。 The consumer will then listen to the queue indicated in the message, consume all the messages in that queue, and finally delete it when done.然后,消费者将监听消息中指示的队列,消费该队列中的所有消息,最后在完成后将其删除。

These short lived queues are all created on the fly as data comes in to be processed and cannot be consumed by multiple consumers (whichever gets the message in the 'ready' queue).这些短暂的队列都是在数据进入以进行处理时动态创建的,并且不能被多个消费者消费(以“就绪”队列中的消息为准)。

I'm having trouble gracefully handling the consumers in this situation.在这种情况下,我无法优雅地处理消费者。 Right now I just create a new DirectMessageListenerContainer each time a consumer gets a message from the 'ready' queue and then stop it once it has gotten all the messages it needs.现在,每当消费者从“就绪”队列中获取消息时,我只需创建一个新的DirectMessageListenerContainer ,然后在它获得所需的所有消息后停止它。 It seems like this solution isn't ideal.看起来这个解决方案并不理想。 Is there any better way to handle a situation like this with Spring AMQP/RabbitMQ?有没有更好的方法来使用 Spring AMQP/RabbitMQ 来处理这种情况?

You can add/remove queues to/from existing container(s) at runtime;您可以在运行时向现有容器添加/删除队列; it is more efficient with the direct container (see Choosing a container ).使用直接容器更有效(请参阅选择容器)。

The MessageProperties has the consumerQueue property to tell you which queue the message came from. MessageProperties具有consumerQueue属性来告诉您消息来自哪个队列。

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

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