Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Amazon's SQS notify one of my "worker" servers whenever there is something in the queue?

I'm following this tutorial: http://boto.s3.amazonaws.com/sqs_tut.html

When there's something in the queue, how do I assign one of my 20 workers to process it?

I'm using Python.

like image 571
TIMEX Avatar asked Nov 14 '10 00:11

TIMEX


People also ask

How are messages Access in Amazon SQS?

AWS SQS helps in sending, storing, and receiving messages without the fear of losing them in the process. These messages can store up to 256 KB of data as text in formats such as JSON, XML, etc. All these messages can be retrieved by the applications with the use of AWS SQS API.

How does an SQS queue work?

Amazon SQS is a distributed queue system that allows applications to queue messages that are generated by one component and consumed by another component. SQS acts as a temporary repository for messages and is used in situations where the messages are produced at a higher rate but get processed at a lower rate.

What is SQS notification?

Amazon SQS is a message queue service used by distributed applications to exchange messages through a polling model, and can be used to decouple sending and receiving components—without requiring each component to be concurrently available.

How does Amazon Simple Queue Service deliver messages?

Standard queues support at-least-once message delivery, and FIFO queues support exactly-once message processing. Availability – Amazon SQS uses redundant infrastructure to provide highly-concurrent access to messages and high availability for producing and consuming messages.


2 Answers

Unfortunately, SQS lacks some of the semantics we've often come to expect in queues. There's no notification or any sort of blocking "get" call.

Amazon's related SNS/Simple Notification Service may be useful to you in this effort. When you've added work to the queue, you can send out a notification to subscribed workers.

See also:

http://aws.amazon.com/sns/

Best practices for using Amazon SQS - Polling the queue

like image 70
Nicholas Knight Avatar answered Oct 21 '22 11:10

Nicholas Knight


This is (now) possible with Long polling on a SQS queue.

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/Query_QueryReceiveMessage.html

Long poll support (integer from 1 to 20) - the duration (in seconds) that the ReceiveMessage action call will wait until a message is in the queue to include in the response, as opposed to returning an empty response if a message is not yet available.

If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait.

Type: Integer from 0 to 20 (seconds)

Default: The ReceiveMessageWaitTimeSeconds of the queue.

like image 24
opepin Avatar answered Oct 21 '22 11:10

opepin