简体   繁体   English

Spring AMQP Rabbit-单个消费者正在监听多个队列-交货顺序是什么?

[英]Spring AMQP Rabbit - single consumer listening to multiple queues - what is the delivery order?

Let me first make sure I explain the problem : 让我首先确保我解释了这个问题

I have to process multiple queues that are filled, in the order they were actually created. 我必须按实际创建的顺序处理多个已填充的队列。 This means that if the queues contain: 这意味着如果队列包含:

q1: m1, m2, m5, m7 q1:m1,m2,m5,m7

q2: m3, m6, m9 q2:m3,m6,m9

q3: m4, m8 q3:m4,m8

I would like to process them so that m4 does not process before m1, m2, or m3. 我想对其进行处理,以使m4不在m1,m2或m3之前处理。 m3 can execute anytime (it does not have to wait for m1 and m2, but it is ok for it to wait since it will most likely be simpler/safer to implement). m3可以随时执行(不必等待m1和m2,但是可以等待它,因为它很可能实现起来更简单/更安全)。 and m8 does not process until m7 is processed. 并且m8在处理m7之前不会处理。

I know it would serialize the effort - but using multiple threads, and I already have locking on some other value in the payload helps ensure that they won't step on each other and gain some amount of parallel processing. 我知道它将串行化工作量-但是使用多个线程,并且我已经在有效负载中锁定了其他一些值,这有助于确保它们不会互相踩踏并获得一定数量的并行处理。

We just ran into issues that q3 processed before the records in q1 and q2, so it couldn't actually do what it was supposed to do. 我们只是遇到了第3季度在第1季度和第2季度的记录之前处理的问题,因此它实际上无法执行应做的事情。 q1 and q2 do take longer to process, and we expect to have more records put into those queues as well. q1和q2确实需要花费更长的时间来处理,并且我们希望将更多的记录放入这些队列中。

I have requested that the sender change to a single queue, but I'm not sure they will be making this change (different team, different priorities), so I am trying to have a realistic backup plan. 我已请求将发件人更改为一个队列,但是我不确定他们是否会进行此更改(不同的团队,不同的优先级),因此我试图制定一个切合实际的备份计划。

Now here is my actual question: I've seen that you can have 1 listener for multiple queues - is there any documentation on the order in which I would receive the messages? 现在这是我的实际问题:我已经看到您可以为多个队列使用1个侦听器-在接收消息的顺序上是否有任何文档? Is it just a round robin, always taking the oldest record from each queue? 难道只是一个轮循,总是从每个队列中提取最早的记录吗? Or is it always the oldest record from all queues it is listening to that is delivered to my listener? 还是它始终是它正在侦听的所有队列中最古老的记录,并传递给我的侦听器?

It depends on the prefetch, by default, the prefetch is 1, which means the broker will deliver 1 message and wait for an ack. 它取决于预取,默认情况下,预取为1,这意味着代理将传递1条消息并等待确认。 The prefetch applies to the channel (across all the queues). 预取适用于通道(跨所有队列)。

If the container concurrentConsumers is 1 (default), they will be processed serially, but the order is indeterminate - it depends on how the broker delivers them. 如果容器concurrentConsumers为1(默认值),则将按顺序处理它们,但是顺序不确定-这取决于代理如何传递它们。 I don't know the internal algorithm used by rabbitmq when a single channel has consumers on multiple queues; 当单个通道在多个队列上有使用者时,我不知道rabbitmq使用的内部算法。 it's best to assume it's indeterminate. 最好假设它是不确定的。

I have requested that the sender change to a single queue, 我已要求发件人更改为单个队列,

A producer publishes to an exchange with a routing key - he shouldn't care about the queue topology downstream. 生产者使用路由密钥发布到交换-他不关心下游的队列拓扑。 The consumer decides the queue topology by binding to that exchange - if you change the exchange to a fanout you can bind a single queue to it and you'll get messages in order, regardless of the routing key the producer uses. 使用者通过绑定到该交换来决定队列拓扑-如果将交换更改为扇出,则可以将单个队列绑定到该扇出,并且不管生产者使用的路由密钥如何,都将按顺序获取消息。

If the producer "owns" the exchange and won't change it, you can bind a fanout exchange to his exchange and bind your single queue to that. 如果生产者“拥有”该交换并且不进行更改,则可以将扇出交换绑定到其交换,并将单个队列绑定到该交换。

Of course, if he adds queues to his exchanges, messages will accumulate there. 当然,如果他将队列添加到他的交换中,则消息将在那里积累。

But, as I said, producers need not be involved in the queue topology. 但是,正如我所说,生产者不必参与队列拓扑。

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

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