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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With