Amazon Simple Queue Service (SQS)

I created a queue in SQS, added two messages (PHP serialized arrays: array('filename' => 0,...) and array('filename' => 1,...) ). I am using the latest amazon SDK for PHP from my git repository.

The problem is that when I use the receive_message function with the following parameters:

 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 Asi72t / UOhbdXhTp3kaCaZfd2weymg = <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 Asi72t / UOhbdXhTp3kaCaZfd2weymg = <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 am 100% sure that there are only 2 messages in the queue (I deleted them and re-created them to be sure), and yet I get only the first one, filled many times. This changes from time to time, and sometimes I get a second list in the list. If I leave VisibilityTimeout as the default value of 3 (or another non-zero value), then the first will disappear for a while (as expected), and then I will 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 not working or am I doing something wrong?

+4
source share
1 answer

I believe this is the expected behavior because you have set VisibilityTimeout = 0 . Typically, you should set the timeout value to the expected processing time of the message. You must call delete in the read message before the visibility time expires or the message is automatically reordered.

On more complex systems, a separate thread can be used to increase the wait time for a single message if the initial timeout was not long enough.

It seems that you are just starting, it is important that you write your message processing code to your account to read the same message several times. Not only can your message be automatically re-recognized, but SQS will sometimes return a duplicate message.

+8
source

Source: https://habr.com/ru/post/1343687/


All Articles