简体   繁体   English

一个 SQS 轮询器能否处理多个 SQS 队列并确定其优先级?

[英]Can one SQS poller, handle multiple SQS queues and prioritize it?

I have a use-case where I have 2 SQS queues, each are getting messages.我有一个用例,其中有 2 个 SQS 队列,每个队列都在获取消息。 But the condition is if I am getting messages in the FIRST queue, I would stop reading messages from SECOND queue and give priority to the FIRST queue message.但条件是如果我在 FIRST 队列中获取消息,我将停止从 SECOND 队列读取消息并优先处理 FIRST 队列消息。 Can I handle this using just one SQS poller?我可以只使用一个 SQS 轮询器来处理这个问题吗?

Problem Statement: I often get messages in the FIRST queue, but those are important messages.问题陈述:我经常在 FIRST 队列中收到消息,但这些都是重要的消息。 But I constantly keep on getting messages in the SECOND queue.但是我不断地在 SECOND 队列中获取消息。 So, if the poller is processing the message of the SECOND queue, and all of a sudden if a new message comes up in the FIRST queue, then after processing the message of the SECOND queue, it should jump to the FIRST queue and start taking the messages from there until the FIRST queue is empty.所以,如果轮询器正在处理第二个队列的消息,并且突然有新消息出现在第一队列中,那么处理完第二队列的消息后,它应该跳转到第一队列并开始取消息从那里直到第一个队列为空。

Is there a solution to it?有解决办法吗?

This is a good way to process priority messages.这是处理优先消息的好方法。

If you have just one consumer (you call it a 'poller') of messages, then it should:如果您只有一个消息消费者(您称之为“轮询器”),那么它应该:

  • Retrieve and process message(s) from the Priority queue优先队列中检索和处理消息
  • If that queue is empty, then retrieve and process message(s) from the Normal queue如果该队列为空,则从普通队列中检索和处理消息

You would need to code this behaviour into your consumers.您需要将此行为编码到您的消费者中。 There is no in-built capability to poll from multiple queues.没有从多个队列轮询的内置功能

If you are running multiple consumers , then you might want to have every consumer do the above, or you could assign a portion of them to only process from a specific queue.如果您正在运行多个消费者,那么您可能希望让每个消费者都执行上述操作,或者您可以将其中的一部分分配给仅来自特定队列的进程。 For example:例如:

  • Some consumers could only poll from the Priority queue , using Long Polling to reduce the number of calls but respond as soon as a message appears in the Priority queue一些消费者只能优先级队列中轮询,使用长轮询来减少调用次数,但在优先级队列中出现消息时立即响应
  • Other consumers could only poll from the Normal queue , to ensure that these messages are receiving attention too其他消费者只能Normal 队列中轮询,以确保这些消息也受到关注
  • You could adjust the relative number of consumers based upon typical data volumes您可以根据典型数据量调整消费者的相对数量

Alternatively, you could decide to use AWS Lambda functions to process your messages .或者,您可以决定使用 AWS Lambda 函数来处理您的消息 In this case, queues would be handled in parallel, but without giving one queue priority over the other.在这种情况下,队列将被并行处理,但不会给予一个队列高于另一个队列的优先级。 The only way to assign priority in such a situation would be to assign different concurrency values to the Lambda functions being used for each queue.在这种情况下分配优先级的唯一方法是为每个队列使用的 Lambda 函数分配不同的并发值 This would give the Priority queue more concurrency in case of capacity limits being reached.如果达到容量限制,这将使优先级队列具有更多的并发性。

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

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