views:

250

answers:

3

I am creating a mass mailer application, where a web application sets up a email template and then queues a bunch of email address for sending. The other side will be a Windows service (or exe) that will poll this queue, picking up the messages for sending.

My question is, what would the advantage be of using SQL Service Broker (or MSMQ) over just creating my own custom queue table?

Everything I'm reading is suggesting I use Service Broker, but I really don't see what the huge advantage over a flat table (that would be a lot simpler to work with for me). For reference the application will be used to send 50,000-100,000 emails almost daily.

A: 

For advantages of Service Broker see this link:

http://msdn.microsoft.com/en-us/library/ms166063.aspx

In general we try to use a tool or standard functionality rather than building things ourselves. This lowers the cost and can make upgrading easier.

Shiraz Bhaiji
Thanks, I have already read that article. My question is, in my case are those advantages listed enough to out way the extra learning curve and complexity.My custom table would be very simple and it would basically come down to 3 statements.Pseudocode:INSERT INTO QueueSELECT * FROM Queue WHERE Completed = falseUPDATE Queue SET Completed = true
Luke
Without service broker you have to watch out for threading. Based on your code what will happen if new rows are added after the select but before the update. If your code crashes will emails be sent twice?
Shiraz Bhaiji
+6  A: 

Do you know how to implement a queue over a flat table? This is not a silly question, implementing a queue over a table correctly is much harder than it sounds. Queue-like-tables are notoriously deadlock prone and you need to carefully consider the table design and the enqueue and dequeue operations. Also, do you know how to scale your pooling of the table? And how are you goind to handle retries and timeouts (ie. what timers are used for)?

I'm not saying you should use SSB. The lerning curve is very steep and is primarily a distributed applicaiton platform, not a local queueing product so some features, like dialogs, will actually be obstacles for you rather than advantages. I'm just saying that you must consider also the difficulties of flat-table-queues. If you never implemented a flat-table-queue then be warned, there are many dragons under that bridge.

50k-100k messages per day is nothing, is only one message per second. If you want 100k per minute, then we have something to talk about.

Remus Rusanu
Thanks for the response. I knew I would have a lot to deal with whichever route I took. Do you have articles or sample applications that could get me pointed in the right direction? Everywhere I search I just keep getting more questions and less sure of what I'm doing.
Luke
Unfortunately I don't. I had searched myself for such articles in the past at most reliable sources (MVP blogs, sqlserverpedia, sqlmag etc etc) but couldn't find a good sum up article. Some advice I have from my own experience: steer clear of anything fancy (like priorities) just try to get the FIFO enqueue/dequeue right (no blocking and deadlock free). Also make sure you use the queue for *events*, not for state. Ie. enqueue the 'request to send this email', not the email itself.
Remus Rusanu
A: 

If you every need to port to another vendor's database, you will have less problem if you used normal tables.

As you seem to only have one reader and one write from your queue, I would tend to use a standard table until you hit problem. However if you start to feel the need to use “locking hints” etc, that the time to switch to the Service Broker Queues.

I would not use MSMQ, if both the sender and the reader need a database connection to work. MSMQ would be good if the sender did not talk to the database at all, as it lets the sender keep working when the database is down. However having to setup and maintain both the MSMQ and the database is likely to be more work then it is worth for most systems.

Ian Ringrose
Thank you. I think I'll (very carefully) trial it with a flat table and see how it performs as this will be the quickest to implement. If I find that it's not up to scratch I'll switch over to Service Broker.
Luke