amazon sqs :read message not in order

2019-06-06 17:43发布

问题:

i would like to take messages from amazon sqs in the same order in which it is inserted into sqs ( first in first out model). Is their any way to implement it?? I am using zend php for programing.

回答1:

Unordered message delivery is inherent in the design of SQS. You could try to work around it by numbering the messages and storing the out-of-order messages locally until the missing messages arrive, but its probably not worth the hassle.

SQS is really a bit of an odd duck, it does what it says, but what it does isn't what most people are looking for in a message bus. I really wish Amazon would offer and additional queuing solution more like RabbitMQ. SQS is really only suited for distributing tasks that aren't even remotely coupled, and where things like order and latency aren't important. For instance it would be great for sending completed orders to a shipping center, or perhaps scheduling print jobs.

Their own documentation shows it being used to schedule thumbnail creation, but when I recently used it for this exact purpose I quickly discovered that my users weren't going to be impressed with the latency: which at times is 30-50 seconds.

You can still run RabbitMQ on EC2 nodes, and while not as scalable as SQS it does cluster and should take you pretty far.



回答2:

You could try IronMQ. It is hosted like SQS, has guaranteed first in first out ordering, no eventual consistency delays, is uber scalable and you can be up and running in minutes.

Here's a PHP library for it: https://github.com/iron-io/iron_mq_php

Disclaimer: I work for Iron.io



回答3:

The SQS documentation answers this for you (bold is my emphasis to directly answer your question):

Amazon SQS makes a best effort to preserve order in messages, but due to the distributed nature of the queue, we cannot guarantee you will receive messages in the exact order you sent them. If your system requires that order be preserved, we recommend you place sequencing information in each message so you can reorder the messages upon receipt.



回答4:

I have tried to implement the FIFO fashion for receiving the messages in the same order they were sent

For this you can use message sequence no which it sent every time with message and validate at the receiver end

By Using this way you can get desired output in FIFO order