问题
Here's my situation:
I have a script that gets raw data, saves it in the database, get the item id then posts it to an amazon SQS queue.
I have another script (written in PHP) that retrieves the raw data from the db and processes it. (it takes a couple of minutes usually.
The missing part is how to retrieve the messages from SQS to be processed. The frequency of new data to process varies, it can go from a few items per hours to dozens of items per minute.
One way would be to have a cron job that queries SQS for new messages and launch the processing script (It would have to be multi-threaded and written in something other than php. Python or Ruby perhaps). The problem wit the cron is that it is pretty inefficient, in high load phases it would be overwhelmed and in quiet phases it would be doing useless calls.
What I would like to have is some kind of multi-threaded listener that would receive messages and process them. One important requirement is to have the raw data processed in a timely manner, a couple of minutes after being received at most.
Any thoughts on the best solution? Is SQS appropriate for the task? What's the most efficient way to listen and process the queue?
来源:https://stackoverflow.com/questions/8203531/processing-items-in-sqs-queue-with-a-php-script