fetch sqs message visibility_timeout in aws using ruby

时间:2016-07-11 22:54:56

标签: amazon-web-services amazon-sqs

in sqs, is there any way i can get visibility_timeout of a message? I plan to double visibility_timeout every it's expired. If SQS has no such API can fetch visibility_timeout of a message, i will need maintain a separate mapping.

2 个答案:

答案 0 :(得分:0)

Here is the syntax to get the visibility time our for an SQS queue. That GetQueueAttributes will give you the value for visibility time out.

http://sqs.us-east-1.amazonaws.com/123456789012/testQueue/
?Action=GetQueueAttributes
&AttributeName.1=All
&Version=2012-11-05
&Expires=2013-10-18T22%3A52%3A43PST
&AUTHPARAMS

The response for above request will be as follows.

<GetQueueAttributesResponse>
  <GetQueueAttributesResult>
    <Attribute>
      <Name>ReceiveMessageWaitTimeSeconds</Name>
      <Value>2</Value>
    </Attribute>
    <Attribute>
      <Name>VisibilityTimeout</Name>
      <Value>30</Value>
    </Attribute>
    <Attribute>
      <Name>ApproximateNumberOfMessages</Name>
      <Value>0</Value>
    </Attribute>
    <Attribute>
      <Name>ApproximateNumberOfMessagesNotVisible</Name>
      <Value>0</Value>
    </Attribute>
    <Attribute>
      <Name>CreatedTimestamp</Name>
      <Value>1286771522</Value>
    </Attribute>
    <Attribute>
      <Name>LastModifiedTimestamp</Name>
      <Value>1286771522</Value>
    </Attribute>
    <Attribute>
      <Name>QueueArn</Name>
      <Value>arn:aws:sqs:us-east-1:123456789012:qfoo</Value>
    </Attribute>
    <Attribute>
      <Name>MaximumMessageSize</Name>
      <Value>8192</Value>
    </Attribute>
    <Attribute>
      <Name>MessageRetentionPeriod</Name>
      <Value>345600</Value>
    </Attribute>
  </GetQueueAttributesResult>
  <ResponseMetadata>
    <RequestId>1ea71be5-b5a2-4f9d-b85a-945d8d08cd0b</RequestId>
  </ResponseMetadata>
</GetQueueAttributesResponse>

答案 1 :(得分:0)

请务必理解开发者指南中的Visibility Timeout

当您收到消息时,可见性计时器将启动。没有办法在收到的邮件上查询它 - 您可以通过从您在邮件中停留的时间减去队列的默认值来计算收到的时间...或者减去自上次设置可见性超时以来的时间,从您设置它的时间量开始。

加倍超时可能不是最好的计划,因为它有一个最大值,你可能会在几次加倍后无意中击中,并且在许多或大多数应用程序中,增加可见性超时应该是不必要的。这可能表明您正在考虑在其预期设计之外使用S3。

此外,单个队列限制为120,000个正在进行的消息,其中包括您已收到但未删除的任何消息 - 包括所有可见性超时(无论是默认还是扩展)的消息都未过期。

并且,更改消息的可见性超时构成了对SQS API的可计费请求。

  

所有SQS API调用都算作请求

     

https://aws.amazon.com/sqs/pricing/

更好,或许,只需将其默认为合理的值,并在合理的时间内更新,如果需要更新。处理并删除邮件后,可见性超时变得毫无意义。

相关问题