Is it possible to proactively clear all SQS messages by MessageGroupId?

0

I am managing our per-customer sub-queues in an SQS FIFO by setting MessageGroupId to the customer id. When one of these customer account is deleted on our end I want to clear out all pending SQS messages with that account's MessageGroupId to save consumer cycles in our workers. Is that possible? Thanks!

已提问 2 年前1071 查看次数
2 回答
0

Have you thought about creating an SQS queue for each customer? That would be a much easier way to manage a task like this in the long term, however; I understand that this may result in application changes. There are deleteMessage and deleteMessageBatch actions, but this requires you to know the message ID. The batch delete also only supports up to 10 messages at a time so depending on the amount of messages in the queue this could add up.

已回答 2 年前
  • My thinking was that if I created a separate FIFO for each customer then I would have to pro-actively poll each one of those queues which wouldn't scale to e.g. 150K customers. Especially since I have two queues that need to be consumed separately and in order: incoming + outgoing. But maybe you can suggest a way around that limitation?

0

There is no API in SQS to do that. You can either create a separate queue per customer, which may be problematic from management point of view and consumers, or, you can add code to the consumer that will verify, before actuall processing the message, that the customer is still active.

profile pictureAWS
专家
Uri
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则