在开发过程中从 SQS 删除消息的最佳方法
在开发过程中,我在 Amazon SQS 上生成了大量虚假消息。我正准备编写一个小应用程序来删除所有消息(这是我在开发过程中经常做的事情)。有人知道清除队列的工具吗?
During development, I'm generating a lot of bogus messages on my Amazon SQS. I was about to write a tiny app to delete all the messages (something I do frequently during development). Does anyone know of a tool to purge the queue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您不想编写脚本或删除队列。您可以更改队列配置:
配置队列
消息保留期
更改为1分钟(可以设置的最短时间)。我发现这种方法非常适合删除队列中的所有消息而不删除队列。
If you don't want to write script or delete your queue. You can change the queue configuration:
configure queue
Message Retention period
to 1 minute (the minimum time it can be set to).I found that this way works well for deleting all messages in a queue without deleting the queue.
截至 2014 年 12 月,sqs 控制台的队列操作菜单中现在有一个清除队列选项。
As of December 2014, the sqs console now has a purge queue option in the queue actions menu.
对于来到这里寻找一种在 C# 中批量删除 SQS 消息的方法的人...
For anyone who has come here, looking for a way to delete SQS messages en masse in C#...
检查队列中的第一项。向下滚动到队列中的最后一项。
按住 Shift 键,单击项目。全部都会被选中。
Check the first item in queue. Scroll down to last item in queue.
Hold shift, click on item. All will be selected.
我认为最好的方法是删除队列并重新创建它,只需 2 个请求。
I think the best way would be to delete the queue and create it again, just 2 requests.
我认为最好的方法是将保留期更改为 1 分钟,但如果有人需要,这里是 Python 代码:
I think best way is changing Retention period to 1 minute, but here is Python code if someone needs:
选项 1:boto sqs 有一个适用于 python 的 purge_queue 方法:
来源:http://boto.readthedocs.org/en/latest/ref/sqs.html
对我有用的代码:
对我来说,它删除了队列。但是,Amazon SQS 仅允许您每 60 秒运行一次。所以我不得不使用下面的辅助解决方案:
选项 2:通过在 while 循环中消耗所有消息并将它们扔掉来进行清除:
Option 1: boto sqs has a purge_queue method for python:
Source: http://boto.readthedocs.org/en/latest/ref/sqs.html
Code that works for me:
For me, it deleted the queue. However, Amazon SQS only lets you run this once every 60 seconds. So I had to use the secondary solution below:
Option 2: Do a purge by consuming all messages in a while loop and throwing them out:
如果您有权访问 AWS 控制台,则可以使用 Web UI 清除队列。
步骤:
这将请求清除队列,这应该在 5 或 10 秒左右完成。
请参阅下文了解如何执行此操作:
If you have access to the AWS console, you can purge a queue using the Web UI.
Steps:
This will request for the queue to be cleared and this should be completed with 5 or 10 seconds or so.
See below for how to perform this operation:
要从 API 中清除 SQS,请参阅:
https://docs.aws .amazon.com/AWSSimpleQueueService/latest/APIReference/API_PurgeQueue.html
To purge an SQS from the API see:
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_PurgeQueue.html