简体   繁体   English

使用 boto 库接收 AWS SQS 队列中的所有消息,直到队列为空

[英]Receive all messages in AWS SQS queue using boto library until queue is empty

I have a case where a script is writing all unused volume ids to AWS SQS queue and after some time, we need to receive all those messages with volume ids and delete those volumes.我有一个脚本正在将所有未使用的卷 ID 写入 AWS SQS 队列的情况,一段时间后,我们需要接收所有带有卷 ID 的消息并删除这些卷。 Is there a way to achieve this using python boto library?有没有办法使用 python boto 库来实现这一点?

Receive all messages in AWS SQS queue using boto library until queue is empty使用 boto 库接收 AWS SQS 队列中的所有消息,直到队列为空

Your Python script should use the boto3 receive_message() command:您的 Python 脚本应该使用 boto3 receive_message()命令:

Retrieves one or more messages (up to 10), from the specified queue.从指定队列中检索一条或多条消息(最多 10 条)。

Once your program has finished processing a message, it should call delete_message() or delete_message_batch() to delete the message, passing the ReceiptHandle for each message that was obtained from the receive_message() call.一旦您的程序处理完消息,它应该调用delete_message()delete_message_batch()来删除消息,为从receive_message()调用获得的每条消息传递ReceiptHandle

To process all messages in the queue, continue receiving and deleting messages within a loop.要处理队列中的所有消息,请在循环中继续接收和删除消息。

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

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