Editorials

Message Queues in SQL Followup

Greg writes in as a response to using an SQL Server table as a queue instead of a queuing service. His requirements are simple, and this method works well for them.

Regarding your question about queues in SQL Server, we have an application that uses SQL Server as a queue for emails. We decided to take this approach instead of using MSMQ to avoid to added software of MSMQ and keep the process simple. Another reason for taking this approach was to separate the email component from our main application which improved performance within the user process and allowed for times when email was down and the queue sent the emails out once the email was back up and running.

When our application needs to send emails, it writes the needed information to a table and continues with the user process within the application. The fields are seq, token, messageID, createdate, senddate. The seq is a unique identifier, token provides the information about the specific users session, messageID identifies the unique email template to email, createdate is the datetime the record was created in the queue, and senddate gets updated with datetime when the email is actually sent out of the queue.

We have a separate application that runs on a scheduled basis that queries this table to get the emails that have not been emailed and once sent, updates the senddate field and also updates the contact record with email. Lastly we clear old sent emails to keep this table as small as possible.

The felt need here was to be able to schedule an email to be delivered, and allow the software making the call to continue without delay. That works pretty well in this case. Sometimes we want something a little more sophisticated which may even be available outside our data center. Perhaps Azure Queues or Service Bus Queues may be a better fit. Maybe you are not using Windows and have software specific for your operating system. Why not share what tools you use, and what scenarios you find queuing to be effective?

Comments may be left here, or sent to btaylor@sswug.org.

Cheers,

Ben