【发布时间】:2013-02-03 10:23:08
【问题描述】:
当我在 AWS 控制台的 SQS 消息视图中查看消息时,我可以看到消息有发送时间。如何使用 Python 的 boto 库读取这些数据?
【问题讨论】:
标签: python amazon-web-services boto amazon-sqs
当我在 AWS 控制台的 SQS 消息视图中查看消息时,我可以看到消息有发送时间。如何使用 Python 的 boto 库读取这些数据?
【问题讨论】:
标签: python amazon-web-services boto amazon-sqs
您可以使用 get_message() 方法的 attributes 参数。请参阅documentation。
queue.get_messages(attributes=['All'])
documentation 还说您可以使用 read() 方法执行此操作,但现在已损坏。我在项目网站上为此打开了一个问题:https://github.com/boto/boto/issues/2699。
【讨论】:
当您从 boto 中的队列中读取消息时,您会得到一个 Message 对象。该对象具有名为attributes 的at 属性。它是 SQS 保存的有关此消息的属性字典。它包括SentTimestamp。
【讨论】:
attributes 在 boto 2.8.0 中的 q.get_messages(10) 之后为空 {}
get_messages 不返回任何属性。您必须通过attributes 参数指定要返回的属性。这可以具有以下值:All|SenderId|SentTimestamp|ApproximateReceiveCount|ApproximateFirstReceiveTimestamp
ALL 还是All。服务期望后者。
attributes 参数实际上需要一个属性名称列表。我刚试过:q.get_messages(attributes=['All']),它对我有用。