Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Mass Transit - Part 1 of N

This post is the first in a series of posts I plan to do about MassTransit, an open source messaging system written by Dru Sellers (blog) and Chris Patterson.  I plan on blogging my observations as I explore both the implementation and the source code.  Before I dig into MassTransit specifically, I want first touch on a few introductory items.

What Is Messaging?

Messaging quite simply is a type of notification.  In the real-world we deal with this everyday.  Consider meeting someone for the first time and you say, "Hello, my name is <your name>."  You've published a message.  If the person on the end is polite, they will have "subscribed" to your message and choose to publish one back, for example, "Nice to meet you <your name>, my name is <their name>."  Another example is someone shouting, "FIRE!" in a crowded theatre.  That is a type of message, albeit an important one.

In code, some messages are rigidly defined, such as when an event is raised.  Many messages, however are more loosely defined.  Consider for example the creation of a string, a log message if you will, that is stored in an in-memory queue.

Can I Benefit From Messaging?

Maybe, maybe not.  Once upon a time I worked for a company that offered a CMS product as part of it's product offerings.  This system started small but gradually had increased demands in the form of new features clients wanted added.  Pretty soon, when you clicked the save button multiple things were happening; a database row would be updated, an email would be sent, a new file would be written, another status file would be updated.  These were all executed when the user clicked the button, therefore every action was a blocking action, the server couldn't move on until it was done servicing that particular request.  Performance degradation wasn't a problem when only one or two things were happening but as users demanded more features performance suffered, which manifested itself in long page loads.

In this example many of the things the application did after the user clicked the save button could have been moved to an asynchronous processing mechanism.  This is where messaging comes in handy, instead of doing all of those tasks in a blocking form you end up instead publishing messages and let some other process come along and do the work for you, asynchronously.  This provides for a much quicker and scalable system.  For example:

   1: public void Save(Entity entity)
   2: {
   3:     EntityRepository.Save(entity);
   4:     
   5:     Publish(ShouldSendEmailMessage);
   6:     
   7:     Publish(WriteFileMessage);
   8:     
   9:     Publish(UpdateStatusFileMessage);
  10: }

What Makes MassTransit different?

MassTransit is based on the idea of durability.  To explain durability I will point you to the title of an MSDN article by Udi Dahan named "Build Scalable Systems That Handle Failure Without Losing Data".  Durable messages means that the message can survive some outside event, such as a server reboot or a process recycling.  Imagine my in-memory queue scenario above.  Image the queue has 50 messages when the server reboots. Where do the messages go?  Since the messages were stored in-memory until they were handled, they are now lost.  In other words, these messages were not durable, data was lost.

Poor Man's Durable Messaging

I recently came across an application that chose to write the properties of an email to a database table rather than attempt to send the email real-time (for performance reasons).  In this particular instance there was another simple .NET console application that ran every few minutes that would look at the database table and see if there was anything in it, if there was it would pull the records and loop through each one sending an emailing and deleting the record after the email was sent.

Durable, yes.  Scalable. No.

Tell Me Why I Need It?

I can hear you now, you're probably thinking, "Hey that database table idea is pretty slick.  I'm doing the same thing in my app and it works fine.  Why do I need a whole new framework to do this?"  The problem that MassTransit seeks to solve is that of scalability.  The database table for emails works well if all you have to do is send emails.  The more messages you want to handle the more database tables you have to add.  Want to add a row to an audit database whenever an action happens, you have set up the database table to hold the information you want the consuming application to handle.  In other words for N types of messages you have to do N things; and that's bad when you want to scale.

Why MassTransit and not NServiceBus?

The reasons I chose to explore MassTransit and not NServiceBus are not scientific at all.  You may not agree with them, and that is fine, but I'm providing them here so you know why:

  • Familiar and Friendly Authors - Dru Seller is one of the nicest guys I met while in Seattle at Alt.NET.  If I have questions or comments about MassTransit, I just pick of the phone and give Dru a call.  Granted not all of you have that ability, but again, I said these were my reasons.  If you are friends with Udi Dahan, I'd strongly suggest you take a look at NServiceBus.
  • Familiar Commonality - MassTransit uses and integrates with other frameworks/libraries that I use, most notably it's integration with Windsor/MicroKernel and secondly NHibernate.
  • Relatively Small - MassTransit is small, yet powerful, and covers the functionality I need.  Being small and young, it is easier for me to go through the project and it's history.

Posted 10-13-2008 5:05 PM by Tim Barcz
Filed under:

[Advertisement]

Comments

Ben Scheirman wrote re: Mass Transit - Part 1 of N
on 10-13-2008 7:56 PM

nice write up!

Thought in your code sample, wouldn't it  be more loosely coupled if you had:

public void Save(Entity entity)

{

    EntityRepository.Save(entity);

    Publish(EntitySavedMessage);

}

And then you'd have services that subscribe to that message and

*  send email

*  log the event

*  etc

Tim Barcz wrote re: Mass Transit - Part 1 of N
on 10-13-2008 9:37 PM

@Ben

Totally agree...actually Dru suggested I change the implementation but the fear was it wouldn't be clear how three distinct actions turned into one "Publish" statement.  The idea was that I would come back to this in a later post and update everyone.

Ultimately you're right though, the implementation above is quicker but not more scalable.

Tim

Mass Transit - Part 1 of N - Tim Barcz « Noocyte’s Weblog wrote Mass Transit - Part 1 of N - Tim Barcz &laquo; Noocyte&#8217;s Weblog
on 10-14-2008 4:57 AM

Pingback from  Mass Transit - Part 1 of N - Tim Barcz &laquo; Noocyte&#8217;s Weblog

Dew Drop - October 14, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - October 14, 2008 | Alvin Ashcraft's Morning Dew
on 10-14-2008 9:13 AM

Pingback from  Dew Drop - October 14, 2008 | Alvin Ashcraft's Morning Dew

Joey Beninghove wrote re: Mass Transit - Part 1 of N
on 10-14-2008 1:20 PM

Very cool.  Looking forward to you digging into it, because I've just started doing the same.  I'm in the process of handrolling some of this stuff and I'm starting to think a service bus like MassTransit might solve most of my infrastructure needs.  My main attraction to MassTransit in particular, is that it seems relatively lightweight, as you mentioned.

DotNetKicks.com wrote Mass Transit - Part 1 of N
on 10-19-2008 12:25 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Tim Barcz wrote Mass Transit - Part 2 of N
on 10-21-2008 11:28 PM

Last week I posted the first in a series on Mass Transit , an open source enterprise messaging system

Community Blogs wrote Mass Transit - Part 2 of N
on 10-22-2008 12:20 AM

Last week I posted the first in a series on Mass Transit , an open source enterprise messaging system

Pharmk727 wrote re: Mass Transit - Part 1 of N
on 02-17-2011 8:23 AM

Hello! eedbfca interesting eedbfca site!

devlicio.us wrote re: Mass Transit - Part 1 of N
on 06-26-2011 6:04 PM

Mass transit part 1 of n.. Nice :)

szd7 porno nwst wrote re: Mass Transit - Part 1 of N
on 07-02-2011 11:37 PM

Mass transit part 1 of n.. Awesome :)

cheap social bookmarking service wrote re: Mass Transit - Part 1 of N
on 01-19-2013 1:53 AM

pJANIA Muchos Gracias for your post.Really looking forward to read more. Fantastic.

pills for weight loss wrote re: Mass Transit - Part 1 of N
on 02-01-2013 3:01 PM

L820BR I am so grateful for your blog post.Much thanks again. Will read on...

generic clomid wrote re: Mass Transit - Part 1 of N
on 02-25-2013 5:02 AM

Uqx3jz Thank you for your blog post.Thanks Again.

buy clomid no prescription wrote re: Mass Transit - Part 1 of N
on 02-28-2013 2:41 PM

aSyFTQ I am so grateful for your blog article.Really looking forward to read more. Awesome.

http://1buyviagrahere.com/ wrote re: Mass Transit - Part 1 of N
on 03-03-2013 6:45 PM

PWw0zt Very informative post. Keep writing.

Social bookmarks wrote re: Mass Transit - Part 1 of N
on 03-24-2013 5:15 PM

MRmRQn Very informative post.Much thanks again. Much obliged.

social bookmarking service wrote re: Mass Transit - Part 1 of N
on 04-03-2013 10:52 PM

PkN2u7 I really enjoy the article.

funny shirts wrote re: Mass Transit - Part 1 of N
on 04-06-2013 12:18 AM

I really like and appreciate your article.Really thank you! Really Cool.

buy social bookmarks wrote re: Mass Transit - Part 1 of N
on 04-14-2013 6:08 AM

oZuvcJ Thank you ever so for you post.Thanks Again. Keep writing.

Social bookmarks wrote re: Mass Transit - Part 1 of N
on 04-19-2013 8:30 PM

mkv8qA Major thankies for the article.

buy social bookmarks wrote re: Mass Transit - Part 1 of N
on 04-23-2013 4:29 PM

aQMu2k Appreciate you sharing, great article.Thanks Again. Keep writing.

camera buying guide wrote re: Mass Transit - Part 1 of N
on 05-13-2013 10:19 PM

8n1Tol Im obliged for the article. Will read on...

modular homes upstate NY wrote re: Mass Transit - Part 1 of N
on 06-05-2013 9:45 AM

1H25Dr I value the post.Much thanks again.

cheap social bookmarks wrote re: Mass Transit - Part 1 of N
on 06-19-2013 7:28 PM

Hw0IsX Great, thanks for sharing this article post.Much thanks again. Cool.

social bookmarks wrote re: Mass Transit - Part 1 of N
on 06-21-2013 8:33 AM

5E2MBc Thank you ever so for you blog post. Great.

news and many more wrote re: Mass Transit - Part 1 of N
on 07-04-2013 11:44 AM

1HHxQx A big thank you for your blog article.Much thanks again. Keep writing.

moldavian news wrote re: Mass Transit - Part 1 of N
on 07-09-2013 9:12 PM

QCHxCm Fantastic blog article.Really looking forward to read more. Much obliged.

news wrote re: Mass Transit - Part 1 of N
on 07-13-2013 2:37 AM

XXOqRH I am so grateful for your blog.Really looking forward to read more. Keep writing.

buy viagra online cheap wrote re: Mass Transit - Part 1 of N
on 07-24-2013 4:19 AM

I loved your article post.Thanks Again. Awesome.

buy cialis online cheap wrote re: Mass Transit - Part 1 of N
on 07-25-2013 6:22 AM

I think this is a real great blog article.Really looking forward to read more. Awesome.

hot news wrote re: Mass Transit - Part 1 of N
on 07-26-2013 11:16 AM

RL2pPM Major thankies for the article.Really looking forward to read more. Fantastic.

buy social bookmarks wrote re: Mass Transit - Part 1 of N
on 07-29-2013 3:04 AM

eOMDxH I think this is a real great article post.Really looking forward to read more. Much obliged.

news news news news wrote re: Mass Transit - Part 1 of N
on 08-04-2013 5:17 PM

zDFU6m Im grateful for the blog post.Much thanks again. Fantastic.

great link buildng wrote re: Mass Transit - Part 1 of N
on 08-19-2013 9:06 AM

OrQ1HL I appreciate you sharing this blog article.Thanks Again. Want more.

great link buildng wrote re: Mass Transit - Part 1 of N
on 08-19-2013 9:58 PM

MxAaYG Wow, great article. Really Great.

great link buildng wrote re: Mass Transit - Part 1 of N
on 08-22-2013 3:54 PM

rf1Xld I really enjoy the article post.Thanks Again. Want more.

seo service wrote re: Mass Transit - Part 1 of N
on 09-06-2013 5:59 PM

W7zVRb Enjoyed every bit of your article post.Really thank you! Fantastic.

online business wrote re: Mass Transit - Part 1 of N
on 09-11-2013 5:45 PM

MIBfof Im obliged for the blog post.Really looking forward to read more. Fantastic.

make money online wrote re: Mass Transit - Part 1 of N
on 09-12-2013 2:05 PM

OkFfux Thanks again for the article.Thanks Again. Really Cool.

cheap link building wrote re: Mass Transit - Part 1 of N
on 09-24-2013 4:24 PM

yCjRJm Thanks for the blog article.Much thanks again. Keep writing.

link building team wrote re: Mass Transit - Part 1 of N
on 09-30-2013 8:04 PM

CCchbD Thanks for the post.Much thanks again. Awesome.

link building team wrote re: Mass Transit - Part 1 of N
on 10-16-2013 6:35 AM

dFFgVm Really informative blog post.Thanks Again. Awesome.

top seo guys wrote re: Mass Transit - Part 1 of N
on 10-25-2013 8:38 PM

YcHKJh Say, you got a nice blog post. Fantastic.

smashing top seo wrote re: Mass Transit - Part 1 of N
on 11-01-2013 4:57 PM

gmoIdK I really like and appreciate your blog post.Really looking forward to read more. Really Cool.

great link building wrote re: Mass Transit - Part 1 of N
on 11-20-2013 10:20 AM

fnDIEY I cannot thank you enough for the blog article. Want more.

seo service wrote re: Mass Transit - Part 1 of N
on 12-15-2013 3:06 AM

PsqpHM Im grateful for the article.Much thanks again. Fantastic.

stunning seo guys wrote re: Mass Transit - Part 1 of N
on 01-10-2014 5:36 PM

kmxffP Thank you ever so for you article.Really looking forward to read more. Fantastic.

nice seo guys wrote re: Mass Transit - Part 1 of N
on 01-17-2014 4:20 PM

NnEkmE I really enjoy the blog article.Really looking forward to read more. Fantastic.

awesome things! wrote re: Mass Transit - Part 1 of N
on 01-21-2014 11:32 AM

JWo5nX Appreciate you sharing, great blog.Much thanks again. Really Cool.

awesome things! wrote re: Mass Transit - Part 1 of N
on 02-28-2014 5:29 AM

UQ67xv Very good blog article. Keep writing.

check out this wrote re: Mass Transit - Part 1 of N
on 03-13-2014 2:54 AM

Bsa19v Muchos Gracias for your blog post. Fantastic.

nice seo guys wrote re: Mass Transit - Part 1 of N
on 03-22-2014 10:33 AM

CA0mIp Thanks again for the article.Really thank you! Keep writing.

best prices wrote re: Mass Transit - Part 1 of N
on 03-22-2014 3:45 PM

zypxBI Hey, thanks for the blog post.Thanks Again. Cool.

best money here wrote re: Mass Transit - Part 1 of N
on 03-25-2014 7:17 AM

RT4sIA I loved your blog post.Really looking forward to read more. Cool.

seo for cheap wrote re: Mass Transit - Part 1 of N
on 03-25-2014 10:41 PM

QVWDPo I appreciate you sharing this blog post.Really thank you!

seo for cheap wrote re: Mass Transit - Part 1 of N
on 04-01-2014 9:30 AM

lI4hdW Thank you ever so for you article post.Much thanks again. Cool.

stunning service wrote re: Mass Transit - Part 1 of N
on 04-04-2014 4:07 PM

3o7I8Z Muchos Gracias for your blog.Thanks Again. Keep writing.

best money here wrote re: Mass Transit - Part 1 of N
on 04-04-2014 9:39 PM

HiIwdR wow, awesome article post.Much thanks again. Really Great.

seo for cheap wrote re: Mass Transit - Part 1 of N
on 04-24-2014 9:05 PM

UeDwRY I cannot thank you enough for the blog.Thanks Again. Will read on...

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)