SQS: 如何使用Python的boto库读取SQS消息的发送时间

8

我在AWS控制台的SQS消息视图中查看消息时可以看到发送时间。如何使用Python的boto库读取此数据?

2个回答

3
当您在boto中从队列中读取消息时,您会得到一个Message对象。此对象具有名为attributes的属性。它是SQS保留有关此消息的属性的字典。其中包括SentTimestamp

1
在boto 2.8.0中,我发现在q.get_messages(10)之后attributes为空{} - jberryman
4
默认情况下,“get_messages”不返回任何属性。您需要通过“attributes”参数指定要返回的属性。可以使用以下值:All|SenderId|SentTimestamp|ApproximateReceiveCount|ApproximateFirstReceiveTimestamp。 - garnaat
我认为boto中存在一个bug - 如果您指定特定的属性,它们将返回(例如:SentTimestamp)。对于我来说,“ALL”也会返回一个空字典。 - L-R
3
你是在使用ALL还是All?该服务需要后者。 - garnaat
无论如何,我得到了相同的结果:空属性和message_attributes列表。 - stuckintheshuck
3
“attributes”参数实际上需要一个属性名称列表。我刚刚尝试了:“q.get_messages(attributes=['All'])”,它对我有效。 - garnaat

2
您可以使用get_message()方法的attributes参数。请参阅文档
queue.get_messages(attributes=['All'])

文档中也提到可以使用read()方法来实现此项功能,但目前该方法存在问题。我已在项目网站上开了一个问题: https://github.com/boto/boto/issues/2699.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接