使用boto3从sqs接收和删除消息

时间:2019-02-20 05:57:47

标签: amazon-web-services queue message boto3 amazon-sqs

我正在尝试一个接一个地接收和删除该消息。这是我的代码供您参考。

def receive_delete(url , attr_names):
    global sqs
    response = sqs.receive_message(QueueUrl=url,
                               AttributeNames=attr_names,
                               MaxNumberOfMessages=10,
                               MessageAttributeNames=['All'])

    delete_msgs = []

    for messages in response['Messages']:

        delete_msgs.append({'Id':messages['MessageId'],
            'ReceiptHandle': messages['ReceiptHandle']})

        while len(delete_msgs) > 0:
            sqs.delete_message(QueueUrl=url , ReceiptHandle=['ReceiptHandle'])

然后我像这样调用该函数...

x = receive_delete("https://sqs.us-east-1.amazonaws.com/266638361021/tony.fifo", attr)

问题是,当我运行此方法时,它卡住了,当我检查Amazon sqs仪表板时,它显示仅删除了一条消息。

如何在收到消息后一一删除?

0 个答案:

没有答案