MSMQ

If you’ve never looked into MSMQ, you should take a few minutes and have a look.  Not necessarily because it’s something you’ll use today, but because it’s cool technology that you probably will have a use for sometime, and if you don’t know about it, you’ll probably reinvent this particular wheel..


MSMQ is a message queueing technology.  It’s been around since Windows 2000, part of the OS, and in my experience anyway, it’s not used all that often. With the .NET framework, it’s really easy to use.


A Queue is a named place where messages go until someone is ready to pick them up.  Here’s some code:



MailItem item = new MailItem();
item.To = “somewhere@somewhere.com”;
item.Subject = “Hello”;
item.Body = “This is an email message.”;


MessageQueue myQueue = new MessageQueue(“.\\Outgoing Email”);
myQueue.Send(myNewEmailObject);


MailItem is an object I’ve defined somewhere.  It supports serialization.  What this code does is create this object, initializes it, and puts it on the “Outgoing Email” queue.  Presumably someone, somewhere, is listening on this queue, and will retrieve my MailItem and actually send an email.


Why not just send the email immediately?  We might need to send an email in the middle of some other operation.. we might need to send an email at a time when we can’t stop what we’re doing and block in an attempt to connect to the mail server.  By putting the item onto the Outgoing Email queue, we’re letting someone else deal with actually getting the message sent, whose job it is to do that, so they’re probably better at it (dealing with retries, logging errors in a standard way, whatever). 


Some benefits of using the queue and a separate sender process:



  • Location Independence.  MSMQ supports public queues, which are registered in the Active Directory.  This means you could have one corporate “Outgoing Email” queue, and any application in the company could post messages onto it.  It doesn’t matter what machine that queue lives on, or what machine the process which is actually sending the emails is running on.


  • Scalability.  More than one process can be listening on a queue, and a message will be given to the first one that asks for it (only).  So if your bottleneck is CPU on one system (which it wouldn’t be in the email example, but humour me), drop down another box and run another instance of the mail sender.  Now they’ll share the load.



  • Resilience.  Queue data persists, so if the power goes out, when it comes back on presumably you’ll be able to pick up where you left off.  Also, if the application that’s sending the messages breaks, messages will queue up until it comes back online.  (Compare this with using something  like .NET Remoting where, if the server is gone, you’re out of luck).

One Usenet posting mentions getting 16k messages a second posted to a queue.. Not bad.


 

Leave a Reply

 




 
buy cheap Endep online buy cheapest Endep and Endep how to order Amitriptyline online without prescription buy Amitriptyline without rx from us pharmacy online Amitriptyline purchase purchase online prescription Amitriptyline without purchasing Amitriptyline online without prescription order generic Amitriptyline buy Endep no prescriptions how to order Endep online without prescription comprare Endep generico Endep online buy Endep in england buy cheap Endep online free consult Endep purchased online without prescription what is Endep Endep tabletten buy Endep no perscription cod Endep non rx fedex overnight free want to buy Anafranil in usa Aricept overdose buy discount Aricept on line Aricept buy Aricept online Aricept order buy Aricept pills Nizoral suppliers cheap order rx Nizoral canada Nizoral order Nizoral usa cod comprar Nizoral generico buy Nizoral 200 mg buy cheap Nizoral under without rx buy cheap Nizoral with dr. prescription Prozac 200 mg buy Lisinopril australia el Nizoral generico buy Lisinopril tablets without rx next day delivery Lisinopril with no script buy Lisinopril c o d purchase arimidex no scams order Arimidex order amex Arimidex canadian pharmacy buy Arimidex without doctor order rx free Arimidex buy Abilify with american express buy Abilify cod order Finpecia without a prescription cheap order rx Finpecia purchase Famvir no visa online without prescription buy Famvir paypal without rx buy Famvir without Famvir without prescription medications Famvir without persription purchase Famvir online no membership overnight shipping Famvir no physician approval Amitriptyline purchase order Amitriptyline free next day airAmitriptyline on line Valtrex no rx needed cod accepted buy next day Fluoxetine buy Fluoxetine line purchase Fluoxetine cod delivery buy Fluoxetine 20 mg purchase Fluoxetine buy cheap Fluoxetine under without rx purchase Fluoxetine visa without prescription Fluoxetine by mail Fluoxetine for pets Fluoxetine 10mg Amitriptyline purchase online how to order Famvir online without a rx Prozac Amitriptyline no perscription Famvir next day purchase Anafranil no prescription cheap buy cheapest Anafranil next day delivery on Anafranil saturday Anafranil buy Anafranil buy Anafranil overnight where to purchase Anafranil no prescription no fees Anafranil drug buy Lisinopril where Lisinopril buy on line order Lisinopril online no membership overnight shipping no prescription required for Lisinopril order maxalt cash on delivery Maxalt from canada buy cheapest Maxalt purchase Maxalt visa without prescription buy Maxalt uk Maxalt 10 mg purchase Maxalt no visa online without prescription purchase generic Lisinopril online Lisinopril no prescription to buy maxalt order online no membership overnight how to get a arimidex rx Aricept without a perscription fedex Aricept overnight without a prescription Donepezil prescription order buy genuine Aricept Aricept uk sales prescription Proscar buy Proscar pay cod Maxalt apotheke buy no perscription Proscar purchase Proscar online buy cheap fedex Prednisone maxalt with no presciption buy Maxalt shipped cod Proscar online Prednisone order buy Amitriptyline with amex Accutane 40 mg delivered overnight buy brand Accutane 40 mg Accutane 40 mg orderd online without prescription where to purchase generic Accutane 40 mg online without a rx how to get 40 mg Accutane without next day delivery 40 mg Accutane with no script buy Amitriptyline online Accutane 40 mg online no prescription buy Accutane 40 mg online us pharmacy Accutane 40 mg best buy buy Accutane 40 mg c o d order 40 mg Accutane cash on delivery no presciption 40 mg Accutane