Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for using Amazon SQS - Polling the queue

I'm designing a service for sending out emails for our eCommerce site (order confirmations, alerts etc...) The plan is to have a "SendEmail" method, that generates a chunk of XML representing the email to be sent, and sticks it on an Amazon SQS queue. My web app(s) and other applications will use this to "send" emails.

I then require a way of checking the queue, and physically sending out the email messages. (I know how I'm going to be dispatching emails)

I'm curious as to what the best way to "poll" the queue would be?

Should I create a windows service, and use something like Quartz.net to schedule it to check the queue every x number of minutes for example? Is there a better way of doing this?

like image 623
Alex Avatar asked Apr 20 '10 22:04

Alex


People also ask

Which is generally preferred SQS long polling or SQS short polling?

In almost all cases, Amazon SQS long polling is preferable to short polling. Long-polling requests let your queue consumers receive messages as soon as they arrive in your queue while reducing the number of empty ReceiveMessageResponse instances returned.

What must be done for long polling to be enabled in SQS?

To enable long polling when creating an Amazon SQS queue, set the ReceiveMessageWaitTimeSeconds attribute on the CreateQueueRequest object before calling the AmazonSQS class' createQueue method.

Which scenarios indicate that you should use an Amazon SQS standard queue?

You can use standard message queues in many scenarios, as long as your application can process messages that arrive more than once and out of order, for example: Decouple live user requests from intensive background work: Let users upload media while resizing or encoding it.

What is poll in SQS?

Amazon SQS provides short polling and long polling to receive messages from a queue. By default, queues use short polling. With short polling, the ReceiveMessage request queries only a subset of the servers (based on a weighted random distribution) to find messages that are available to include in the response.


2 Answers

Sounds more like Amazon SNS is your huckleberry. (not really sure what that means, but I saw it in a movie once).

SQS is more of a "hopefully someone comes looking for this message at some point before it expires!" where SNS seems more like a "I need to make sure this gets to whoever needs it right away!"

It even includes email as a pre-built transport. (not even sure if that's the right word)

Amazon SNS provides a simple web services interface that can be used to create topics you want to notify applications (or people) about, subscribe clients to these topics, publish messages, and have these messages delivered over clients’ protocol of choice (i.e. HTTP, email, etc.). Amazon SNS delivers notifications to clients using a “push” mechanism that eliminates the need to periodically check or “poll” for new information and updates.

To be sure, they have the same freemium model as the rest of the services with limitations on email:

You can get started with Amazon SNS for free. Each month, Amazon SNS customers pay no charges for the first 100,000 Amazon SNS Requests, no charges for the first 100,000 Notifications over HTTP and no charges for the first 1,000 Notifications over Email.

like image 85
sherif Avatar answered Sep 21 '22 13:09

sherif


If I were you, and if I REALLY wanted to make SQS work for this scenario, I would create a windows service that retrieves any messages from the queue every 10 minutes and then dispatches them.

If I could potentially use a different service, I would seriously consider using something like Postmark (Which I just found out about today thanks to a comment on Jeff Atwood’s blog post). You would just submit your email message info to their api, and they would do the rest. They even have a api for checking for bounced emails. I have never used this service, but I think it sounds great and would seriously consider using it in the future.

like image 42
BigJoe714 Avatar answered Sep 25 '22 13:09

BigJoe714