【问题标题】:SQS: How can I read the sent time of an SQS message using Python's boto librarySQS:如何使用 Python 的 boto 库读取 SQS 消息的发送时间
【发布时间】:2013-02-03 10:23:08
【问题描述】:

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

【问题讨论】:

    标签: python amazon-web-services boto amazon-sqs


    【解决方案1】:

    您可以使用 get_message() 方法的 attributes 参数。请参阅documentation

    queue.get_messages(attributes=['All'])
    

    documentation 还说您可以使用 read() 方法执行此操作,但现在已损坏。我在项目网站上为此打开了一个问题:https://github.com/boto/boto/issues/2699

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我发现 attributes 在 boto 2.8.0 中的 q.get_messages(10) 之后为空 {}
      • 默认情况下,get_messages 不返回任何属性。您必须通过attributes 参数指定要返回的属性。这可以具有以下值:All|SenderId|SentTimestamp|ApproximateReceiveCount|ApproximateFirstReceiveTimestamp
      • 我认为 boto 中存在一个错误 - 如果您指定它们将返回的特定属性(例如:SentTimestamp)。 'ALL' 也为我返回一个空字典。
      • 您使用的是ALL 还是All。服务期望后者。
      • attributes 参数实际上需要一个属性名称列表。我刚试过:q.get_messages(attributes=['All']),它对我有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 2014-10-15
      • 2012-04-28
      相关资源
      最近更新 更多