亚马逊简单队列服务 (SQS)

发布于 2024-10-22 02:14:27 字数 1746 浏览 2 评论 0原文

我在 SQS 中创建了一个队列,添加了两条消息(序列化 PHP 数组:array('filename' => 0, ...)array('filename' => 1, ...))。我正在使用来自 git 存储库的最新版本的 amazon SDK for PHP。

问题是,当我使用带有这些选项的 receive_message 函数时:

MaxNumberOfMessages = 10
VisibilityTimeout = 0 // other values doesn't change much

我只收到第一条消息,重复 10 次:

<ReceiveMessageResponse>
−
<ReceiveMessageResult>
−
<Message>
<MessageId>82523332-75e0-444d-ae8f-55ccd5580beb</MessageId>
−
<ReceiptHandle>
v5iiyMGi3b6RunVNVvjOQOV+ZDqRV7sNLzj5pUAEj1brIAkucpYiGaM8UIdOEis9Kouh4s+cAkSAd7MhbJKPGM6SdKYE993x2Lf/DwEbhkfmzRxOevzUsyJCrrVdTSTSx0cNUqqV6Cgr/Asi72t/UOhbdXhTp3kaCaZfd2weymg=
</ReceiptHandle>
<MD5OfBody>ced185420292fbd06b32ea6e35da3d21</MD5OfBody>
−
<Body>
a:3:{s:8:"priority";i:2;s:8:"filename";i:0;s:11:"task_ticket";s:0:"";}
</Body>
</Message>
−
<Message>
<MessageId>82523332-75e0-444d-ae8f-55ccd5580beb</MessageId>
−
<ReceiptHandle>
v5iiyMGi3b6RunVNVvjOQOV+ZDqRV7sNLzj5pUAEj1brIAkucpYiGaM8UIdOEis9Kouh4s+cAkSAd7MhbJKPGM6SdKYE993x2Lf/DwEbhkfmzRxOevzUsyJCrrVdTSTSx0cNUqqV6Cgr/Asi72t/UOhbdXhTp3kaCaZfd2weymg=
</ReceiptHandle>
<MD5OfBody>ced185420292fbd06b32ea6e35da3d21</MD5OfBody>
−
<Body>
a:3:{s:8:"priority";i:2;s:8:"filename";i:0;s:11:"task_ticket";s:0:"";}
</Body>
</Message>
    ...and so on, always with "filename";i:0

我 100% 队列中只有 2 条消息(我删除了它并重新创建以确保)我只得到第一个,填充了很多次。这会不时发生变化,有时我会在列表中混合第二个。如果我将 VisibilityTimeout 保留为默认值 3(或其他非零值),第一个会消失一段时间(如预期),然后第二个会重复很多次。

get_queue_size 返回 2,这是正确的。

我还尝试了 Amazon Scratchpad,只是进行了 API 调用,结果相同。那么,是 SQS 坏了还是我做错了什么?

I created a queue in SQS, added two messages (serialized PHP arrays: array('filename' => 0, ...) and array('filename' => 1, ...)). I'm using the newest version of amazon SDK for PHP from their git repo.

The problem is that when I use receive_message function with these options:

MaxNumberOfMessages = 10
VisibilityTimeout = 0 // other values doesn't change much

I get only the first message, repeated 10 times:

<ReceiveMessageResponse>
−
<ReceiveMessageResult>
−
<Message>
<MessageId>82523332-75e0-444d-ae8f-55ccd5580beb</MessageId>
−
<ReceiptHandle>
v5iiyMGi3b6RunVNVvjOQOV+ZDqRV7sNLzj5pUAEj1brIAkucpYiGaM8UIdOEis9Kouh4s+cAkSAd7MhbJKPGM6SdKYE993x2Lf/DwEbhkfmzRxOevzUsyJCrrVdTSTSx0cNUqqV6Cgr/Asi72t/UOhbdXhTp3kaCaZfd2weymg=
</ReceiptHandle>
<MD5OfBody>ced185420292fbd06b32ea6e35da3d21</MD5OfBody>
−
<Body>
a:3:{s:8:"priority";i:2;s:8:"filename";i:0;s:11:"task_ticket";s:0:"";}
</Body>
</Message>
−
<Message>
<MessageId>82523332-75e0-444d-ae8f-55ccd5580beb</MessageId>
−
<ReceiptHandle>
v5iiyMGi3b6RunVNVvjOQOV+ZDqRV7sNLzj5pUAEj1brIAkucpYiGaM8UIdOEis9Kouh4s+cAkSAd7MhbJKPGM6SdKYE993x2Lf/DwEbhkfmzRxOevzUsyJCrrVdTSTSx0cNUqqV6Cgr/Asi72t/UOhbdXhTp3kaCaZfd2weymg=
</ReceiptHandle>
<MD5OfBody>ced185420292fbd06b32ea6e35da3d21</MD5OfBody>
−
<Body>
a:3:{s:8:"priority";i:2;s:8:"filename";i:0;s:11:"task_ticket";s:0:"";}
</Body>
</Message>
    ...and so on, always with "filename";i:0

I'm 100% that there are only 2 messages in the queue (I deleted it and recreated to be sure) and yet I get only the first one, populated many times. This changes from time to time and sometimes I get the second one mixed in the list. If I leave VisibilityTimeout as default 3 (or other non-zero value) the first one disappears for a while (as expected) and then I get the second one repeated many times.

get_queue_size returns 2, which is true.

I also tried Amazon Scratchpad and just made API calls with the same results. So, is SQS broken or I'm doing something totally wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2024-10-29 02:14:27

我相信这是预期的行为,因为您已设置 VisibilityTimeout = 0。通常,您会将超时值设置为处理消息的预期持续时间。您必须在可见性超时到期之前对已读消息调用delete,否则该消息将自动重新排队。

在更复杂的系统中,如果初始超时不够长,则可以使用单独的线程来延长单个消息的超时期限。

听起来您才刚刚开始,因此编写消息处理代码以考虑多次读取同一消息非常重要。您的消息不仅会自动重新排队,而且 SQS 偶尔会返回重复的消息。

I believe this is expected behavior because you have set VisibilityTimeout = 0. Typically you would set the timeout value to be the expected duration to process a message. You must call delete on a read message before the visibility timeout expires or the message will be automatically re-queued.

In more complex systems a separate thread might be used to extend the timeout period for a single message if the initial timeout was not long enough.

As it sounds like you are just starting, it's important that you write your message processing code to account for reading the same message multiple times. Not only can your message get re-queued automatically but SQS will occasionally return a duplicate message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文