<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Tim Barcz - Mass Transit</title>
    <link>http://www.timbarcz.com/blog/</link>
    <description>My Code is My Craft</description>
    <image>
      <url>http://www.timbarcz.com/blog/content/binary/channelImage.jpg</url>
      <title>Tim Barcz - Mass Transit</title>
      <link>http://www.timbarcz.com/blog/</link>
    </image>
    <language>en-us</language>
    <copyright>Tim Barcz</copyright>
    <lastBuildDate>Wed, 22 Oct 2008 03:34:43 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>blog@timbarcz.com</managingEditor>
    <webMaster>blog@timbarcz.com</webMaster>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=b41943dc-be2b-4ee7-97fc-087a0b090bbb</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,b41943dc-be2b-4ee7-97fc-087a0b090bbb.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,b41943dc-be2b-4ee7-97fc-087a0b090bbb.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b41943dc-be2b-4ee7-97fc-087a0b090bbb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week I posted the <a href="http://devlicio.us/blogs/tim_barcz/archive/2008/10/13/mass-transit-part-1-of-n.aspx">first
in a series on Mass Transit</a>, an open source enterprise messaging system. 
This series is my public exploration into messaging for our eCommerce application. 
In this post I'm going to dig in to see an actual working example.  I like to
see something work, then dig in to figure out how it's all put together.  We'll
take a look at a simple publish subscribe example to see the messaging in action. 
In later posts we'll dig in deeper into the guts of <a href="http://code.google.com/p/masstransit/">MassTransit</a>. 
That said, let's see some <a href="http://code.google.com/p/masstransit/">MassTransit</a> in
action!
</p>
        <p>
          <font size="5">Getting Started</font>
        </p>
        <p>
I've downloaded the MassTransit source from the <a href="http://masstransit.googlecode.com/svn/trunk">Google
Code repository</a> and am going to run one of the samples provided with the source. 
We'll look at their "PublishSubscribe" sample.
</p>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_2.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="191" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb.png" width="571" border="0" />
          </a>
        </p>
        <h2>Project Structure
</h2>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_6.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_2.png" width="301" align="right" border="0" />
          </a> Opening
the solution reveals nine projects, a few more than what I would consider a simple
sample, however don't let the solution scare you away.  It turns out that you
can for the most part ignore five of the projects, the mass transit infrastructure
projects.
</p>
        <p>
There are four parts to this solution that are relevant and we'll focus on those:
</p>
        <ul>
          <li>
            <strong>Client</strong> - The client represents the application that wishes to leverage
messaging.  It plays the role of publisher in this example.  It is worth
noting however that in this example, as we'll see, this project is also a subscriber. 
</li>
          <li>
            <strong>Security Messages</strong> - This is a pretty simple project as it should
be.  This project encapsulates the strongly typed messages that will be passed
throughout the system.  By having the messages in their own light-weight assembly
we can keep our messages separate for their consumers. 
</li>
          <li>
            <strong>Server</strong> - This project acts as the subscriber.  In a normal scenario
this server may be sending out emails or logging particularly interesting things as
messages come through or whatever else you may have a need for.  Like the client
project, we'll see that this project also plays dual roles, the subscriber as mentioned
and also a publisher. 
</li>
          <li>
            <strong>SubMgr</strong> - The subscription manager, is quite a mystery to me. 
It may not be obvious, but the subscription manager is needed to get everything to
work.  As <a href="http://blog.acuriousmind.com/">Dru</a> explains it to me,
it is the glue.  In my first go around with MassTransit, I created a client and
server and was frustrated when nothing was working.  Talking with <a href="http://blog.acuriousmind.com/">Dru</a>,
he quickly pointed out my error, I had no Subscription manager.  In the following
posts I hope to clear up some of the mystery for myself around the subscription manager. 
My understanding at this point of the subscription manager, which may be a bit simplistic,
is that it pushes the messages to each of the queues which are interested in the message. 
A publisher publishes a message, the subscription manager is the one that ensures
that it ends up in the appropriate queue(s) for consumption by various subscribers. 
</li>
        </ul>
        <h2>
        </h2>
        <h2>Getting Setup
</h2>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_26.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="114" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_12.png" width="425" align="right" border="0" />
          </a> In
order to get this sample going you first have to create the MSMQ queues that this
sample expects:
</p>
        <ul>
          <li>
mt_client 
</li>
          <li>
mt_pubsub 
</li>
          <li>
mt_server 
</li>
        </ul>
        <p>
You can create these queues in the <em>Message Queuing</em> area of the <em>Services
and Applications</em> snap-in in the computer management area on your computer.
</p>
        <h2>Seeing Is Believing
</h2>
        <p>
Now that we've got the project set up let's fire it up and see what we get. 
Since we need all three applications running at once, the client, server, and subscription
manager we can take advantage of a cool feature in Visual Studio, multi-project startup.
</p>
        <p>
With multi-project startup you start any number of projects in your solution. 
From the <em>properties</em> dialog for the solution we can choose which projects
we want to kick off.  (It is worth noting the order in which I have these projects
launching.)
</p>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_16.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="340" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_7.png" width="475" border="0" />
          </a>
        </p>
        <h3>What's Going On
</h3>
        <p>
When you run this example, the client application will ask you to enter a new password. 
When you type in a new password  you will get a nearly instantaneous response
letting you know the password was updated.
</p>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_18.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="318" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_8.png" width="620" border="0" />
          </a> 
</p>
        <p>
The thing to bear in mind here is that at the point you hit the &lt;enter&gt; key
submitting your new password, the client publishes a message and then it is done. 
It appears instantaneous but you'll want to keep in mind that it is asynchronous.
</p>
        <h2>The Flow Of It All
</h2>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_22.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="265" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_10.png" width="505" align="right" border="0" />
          </a> The
diagram to the right illustrates what is going on once you hit the &lt;enter&gt; key.
</p>
        <ol>
          <li>
The client publishes a <em>RequestPasswordUpdate</em> message (see the <strong>Security
Messages</strong> project in the solution for this message object). 
</li>
          <li>
The server in this case consumes the <em>RequestPasswordUpdate</em> message. 
When it is notified of the message, it logs the new password, then... 
</li>
          <li>
The Server publishes a new <em>PasswordUpdateComplete </em>message. 
</li>
          <li>
The client consumes the <em>PasswordUpdateComplete </em>message and in so doing writes
to the console that the password update is complete. 
</li>
        </ol>
        <p>
It is worth noting here that the client knows nothing of the server and the server
knows nothing of the client.  Our example could easily expand to have multiple
clients (think for example a windows app or multiple web servers in a farm). 
Likewise there could be multiple server instance, each consuming different messages. 
In other words, we are very loosely coupled, which is a good thing.
</p>
        <h2>Conclusion
</h2>
        <p>
I hope this introduction to the MassTransit was beneficial.  Now that we've seen
the example working, in the next post I'll revisit the idea of durability.  We'll
augment this example and simulate a breakdown in infrastructure and see what durability
really means, which is really at the heart of this fantastic open source library.
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=b41943dc-be2b-4ee7-97fc-087a0b090bbb" />
      </body>
      <title>Mass Transit - Part 2 of N</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,b41943dc-be2b-4ee7-97fc-087a0b090bbb.aspx</guid>
      <link>http://www.timbarcz.com/blog/MassTransitPart2OfN.aspx</link>
      <pubDate>Wed, 22 Oct 2008 03:34:43 GMT</pubDate>
      <description>&lt;p&gt;
Last week I posted the &lt;a href="http://devlicio.us/blogs/tim_barcz/archive/2008/10/13/mass-transit-part-1-of-n.aspx"&gt;first
in a series on Mass Transit&lt;/a&gt;, an open source enterprise messaging system.&amp;#160;
This series is my public exploration into messaging for our eCommerce application.&amp;#160;
In this post I'm going to dig in to see an actual working example.&amp;#160; I like to
see something work, then dig in to figure out how it's all put together.&amp;#160; We'll
take a look at a simple publish subscribe example to see the messaging in action.&amp;#160;
In later posts we'll dig in deeper into the guts of &lt;a href="http://code.google.com/p/masstransit/"&gt;MassTransit&lt;/a&gt;.&amp;#160;
That said, let's see some &lt;a href="http://code.google.com/p/masstransit/"&gt;MassTransit&lt;/a&gt; in
action!
&lt;/p&gt;
&lt;p&gt;
&lt;font size="5"&gt;Getting Started&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
I've downloaded the MassTransit source from the &lt;a href="http://masstransit.googlecode.com/svn/trunk"&gt;Google
Code repository&lt;/a&gt; and am going to run one of the samples provided with the source.&amp;#160;
We'll look at their &amp;quot;PublishSubscribe&amp;quot; sample.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="191" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb.png" width="571" border="0" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h2&gt;Project Structure
&lt;/h2&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_2.png" width="301" align="right" border="0" /&gt;&lt;/a&gt; Opening
the solution reveals nine projects, a few more than what I would consider a simple
sample, however don't let the solution scare you away.&amp;#160; It turns out that you
can for the most part ignore five of the projects, the mass transit infrastructure
projects.
&lt;/p&gt;
&lt;p&gt;
There are four parts to this solution that are relevant and we'll focus on those:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt; - The client represents the application that wishes to leverage
messaging.&amp;#160; It plays the role of publisher in this example.&amp;#160; It is worth
noting however that in this example, as we'll see, this project is also a subscriber. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Messages&lt;/strong&gt; - This is a pretty simple project as it should
be.&amp;#160; This project encapsulates the strongly typed messages that will be passed
throughout the system.&amp;#160; By having the messages in their own light-weight assembly
we can keep our messages separate for their consumers. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt; - This project acts as the subscriber.&amp;#160; In a normal scenario
this server may be sending out emails or logging particularly interesting things as
messages come through or whatever else you may have a need for.&amp;#160; Like the client
project, we'll see that this project also plays dual roles, the subscriber as mentioned
and also a publisher. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SubMgr&lt;/strong&gt; - The subscription manager, is quite a mystery to me.&amp;#160;
It may not be obvious, but the subscription manager is needed to get everything to
work.&amp;#160; As &lt;a href="http://blog.acuriousmind.com/"&gt;Dru&lt;/a&gt; explains it to me,
it is the glue.&amp;#160; In my first go around with MassTransit, I created a client and
server and was frustrated when nothing was working.&amp;#160; Talking with &lt;a href="http://blog.acuriousmind.com/"&gt;Dru&lt;/a&gt;,
he quickly pointed out my error, I had no Subscription manager.&amp;#160; In the following
posts I hope to clear up some of the mystery for myself around the subscription manager.&amp;#160;
My understanding at this point of the subscription manager, which may be a bit simplistic,
is that it pushes the messages to each of the queues which are interested in the message.&amp;#160;
A publisher publishes a message, the subscription manager is the one that ensures
that it ends up in the appropriate queue(s) for consumption by various subscribers. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;h2&gt;Getting Setup
&lt;/h2&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_26.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="114" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_12.png" width="425" align="right" border="0" /&gt;&lt;/a&gt; In
order to get this sample going you first have to create the MSMQ queues that this
sample expects:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
mt_client 
&lt;/li&gt;
&lt;li&gt;
mt_pubsub 
&lt;/li&gt;
&lt;li&gt;
mt_server 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You can create these queues in the &lt;em&gt;Message Queuing&lt;/em&gt; area of the &lt;em&gt;Services
and Applications&lt;/em&gt; snap-in in the computer management area on your computer.
&lt;/p&gt;
&lt;h2&gt;Seeing Is Believing
&lt;/h2&gt;
&lt;p&gt;
Now that we've got the project set up let's fire it up and see what we get.&amp;#160;
Since we need all three applications running at once, the client, server, and subscription
manager we can take advantage of a cool feature in Visual Studio, multi-project startup.
&lt;/p&gt;
&lt;p&gt;
With multi-project startup you start any number of projects in your solution.&amp;#160;
From the &lt;em&gt;properties&lt;/em&gt; dialog for the solution we can choose which projects
we want to kick off.&amp;#160; (It is worth noting the order in which I have these projects
launching.)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_16.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="340" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_7.png" width="475" border="0" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;What's Going On
&lt;/h3&gt;
&lt;p&gt;
When you run this example, the client application will ask you to enter a new password.&amp;#160;
When you type in a new password&amp;#160; you will get a nearly instantaneous response
letting you know the password was updated.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_18.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="318" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_8.png" width="620" border="0" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The thing to bear in mind here is that at the point you hit the &amp;lt;enter&amp;gt; key
submitting your new password, the client publishes a message and then it is done.&amp;#160;
It appears instantaneous but you'll want to keep in mind that it is asynchronous.
&lt;/p&gt;
&lt;h2&gt;The Flow Of It All
&lt;/h2&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_22.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="265" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MassTransitPart2ofN_11CE6/image_thumb_10.png" width="505" align="right" border="0" /&gt;&lt;/a&gt; The
diagram to the right illustrates what is going on once you hit the &amp;lt;enter&amp;gt; key.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
The client publishes a &lt;em&gt;RequestPasswordUpdate&lt;/em&gt; message (see the &lt;strong&gt;Security
Messages&lt;/strong&gt; project in the solution for this message object). 
&lt;/li&gt;
&lt;li&gt;
The server in this case consumes the &lt;em&gt;RequestPasswordUpdate&lt;/em&gt; message.&amp;#160;
When it is notified of the message, it logs the new password, then... 
&lt;/li&gt;
&lt;li&gt;
The Server publishes a new &lt;em&gt;PasswordUpdateComplete &lt;/em&gt;message. 
&lt;/li&gt;
&lt;li&gt;
The client consumes the &lt;em&gt;PasswordUpdateComplete &lt;/em&gt;message and in so doing writes
to the console that the password update is complete. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
It is worth noting here that the client knows nothing of the server and the server
knows nothing of the client.&amp;#160; Our example could easily expand to have multiple
clients (think for example a windows app or multiple web servers in a farm).&amp;#160;
Likewise there could be multiple server instance, each consuming different messages.&amp;#160;
In other words, we are very loosely coupled, which is a good thing.
&lt;/p&gt;
&lt;h2&gt;Conclusion
&lt;/h2&gt;
&lt;p&gt;
I hope this introduction to the MassTransit was beneficial.&amp;#160; Now that we've seen
the example working, in the next post I'll revisit the idea of durability.&amp;#160; We'll
augment this example and simulate a breakdown in infrastructure and see what durability
really means, which is really at the heart of this fantastic open source library.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=b41943dc-be2b-4ee7-97fc-087a0b090bbb" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,b41943dc-be2b-4ee7-97fc-087a0b090bbb.aspx</comments>
      <category>Mass Transit</category>
      <category>Open Source Software</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=988241d7-e4a0-4f01-8d3b-21094761ecc0</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,988241d7-e4a0-4f01-8d3b-21094761ecc0.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,988241d7-e4a0-4f01-8d3b-21094761ecc0.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=988241d7-e4a0-4f01-8d3b-21094761ecc0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This post is the first in a series of posts I plan to do about <a href="http://code.google.com/p/masstransit/">MassTransit</a>,
an open source messaging system written by <a href="http://www.drusellers.com">Dru
Sellers</a> (<a href="http://blog.acuriousmind.com/">blog</a>) and <a href="http://blog.phatboyg.com/">Chris
Patterson</a>.  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.
</p>
        <h2>What Is Messaging?
</h2>
        <p>
          <strong>
            <em>Messaging</em>
          </strong> 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 &lt;your name&gt;."  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
&lt;your name&gt;, my name is &lt;their name&gt;."  Another example is someone
shouting, "FIRE!" in a crowded theatre.  That is a type of message,
albeit an important one.
</p>
        <p>
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.
</p>
        <h2>Can I Benefit From Messaging?
</h2>
        <p>
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.
</p>
        <p>
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:
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">void</span> Save(Entity
entity)</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> {</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span> EntityRepository.Save(entity);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span> Publish(ShouldSendEmailMessage);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 7:</span> Publish(WriteFileMessage);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 9:</span> Publish(UpdateStatusFileMessage);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 10:</span> }</pre>
          </div>
        </div>
        <h2>What Makes MassTransit different?
</h2>
        <p>
MassTransit is based on the idea of durability.  To explain durability I will
point you to the title of an MSDN article by <a href="http://www.udidahan.com">Udi
Dahan</a> named <a href="http://msdn.microsoft.com/en-us/magazine/cc663023.aspx">"Build
Scalable Systems That Handle Failure Without Losing Data"</a>.  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.
</p>
        <h2>
        </h2>
        <h2>Poor Man's Durable Messaging
</h2>
        <p>
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.
</p>
        <p>
Durable, yes.  Scalable. No.
</p>
        <h2>Tell Me Why I Need It?
</h2>
        <p>
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.
</p>
        <h2>Why MassTransit and not NServiceBus?
</h2>
        <p>
The reasons I chose to explore <a href="http://code.google.com/p/masstransit/">MassTransit</a> and
not <a href="http://www.nservicebus.com/">NServiceBus</a> 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:
</p>
        <ul>
          <li>
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. 
</li>
          <li>
Familiar Commonality - MassTransit uses and integrates with other frameworks/libraries
that I use, most notably it's integration with Windsor/MicroKernel and secondly NHibernate. 
</li>
          <li>
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. 
</li>
        </ul>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=988241d7-e4a0-4f01-8d3b-21094761ecc0" />
      </body>
      <title>Mass Transit - Part 1 of N</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,988241d7-e4a0-4f01-8d3b-21094761ecc0.aspx</guid>
      <link>http://www.timbarcz.com/blog/MassTransitPart1OfN.aspx</link>
      <pubDate>Mon, 13 Oct 2008 22:08:48 GMT</pubDate>
      <description>&lt;p&gt;
This post is the first in a series of posts I plan to do about &lt;a href="http://code.google.com/p/masstransit/"&gt;MassTransit&lt;/a&gt;,
an open source messaging system written by &lt;a href="http://www.drusellers.com"&gt;Dru
Sellers&lt;/a&gt; (&lt;a href="http://blog.acuriousmind.com/"&gt;blog&lt;/a&gt;) and &lt;a href="http://blog.phatboyg.com/"&gt;Chris
Patterson&lt;/a&gt;.&amp;#160; I plan on blogging my observations as I explore both the implementation
and the source code.&amp;#160; Before I dig into MassTransit specifically, I want first
touch on a few introductory items.
&lt;/p&gt;
&lt;h2&gt;What Is Messaging?
&lt;/h2&gt;
&lt;p&gt;
&lt;strong&gt;&lt;em&gt;Messaging&lt;/em&gt;&lt;/strong&gt; quite simply is a type of notification.&amp;#160;
In the real-world we deal with this everyday.&amp;#160; Consider meeting someone for the
first time and you say, &amp;quot;Hello, my name is &amp;lt;your name&amp;gt;.&amp;quot;&amp;#160; You've
published a message.&amp;#160; If the person on the end is polite, they will have &amp;quot;subscribed&amp;quot;
to your message and choose to publish one back, for example, &amp;quot;Nice to meet you
&amp;lt;your name&amp;gt;, my name is &amp;lt;their name&amp;gt;.&amp;quot;&amp;#160; Another example is someone
shouting, &amp;quot;FIRE!&amp;quot; in a crowded theatre.&amp;#160; That is a type of message,
albeit an important one.
&lt;/p&gt;
&lt;p&gt;
In code, some messages are rigidly defined, such as when an event is raised.&amp;#160;
Many messages, however are more loosely defined.&amp;#160; Consider for example the creation
of a string, a log message if you will, that is stored in an in-memory queue.
&lt;/p&gt;
&lt;h2&gt;Can I Benefit From Messaging?
&lt;/h2&gt;
&lt;p&gt;
Maybe, maybe not.&amp;#160; Once upon a time I worked for a company that offered a CMS
product as part of it's product offerings.&amp;#160; This system started small but gradually
had increased demands in the form of new features clients wanted added.&amp;#160; 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.&amp;#160; 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.&amp;#160; 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.
&lt;/p&gt;
&lt;p&gt;
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.&amp;#160; 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.&amp;#160; This provides for a much quicker and
scalable system.&amp;#160; For example:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save(Entity
entity)&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; EntityRepository.Save(entity);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; Publish(ShouldSendEmailMessage);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; Publish(WriteFileMessage);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; Publish(UpdateStatusFileMessage);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;What Makes MassTransit different?
&lt;/h2&gt;
&lt;p&gt;
MassTransit is based on the idea of durability.&amp;#160; To explain durability I will
point you to the title of an MSDN article by &lt;a href="http://www.udidahan.com"&gt;Udi
Dahan&lt;/a&gt; named &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc663023.aspx"&gt;&amp;quot;Build
Scalable Systems That Handle Failure Without Losing Data&amp;quot;&lt;/a&gt;.&amp;#160; Durable
messages means that the message can survive some outside event, such as a server reboot
or a process recycling.&amp;#160; Imagine my in-memory queue scenario above.&amp;#160; Image
the queue has 50 messages when the server reboots. Where do the messages go?&amp;#160;
Since the messages were stored in-memory until they were handled, they are now lost.&amp;#160;
In other words, these messages were not durable, data was lost.
&lt;/p&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;h2&gt;Poor Man's Durable Messaging
&lt;/h2&gt;
&lt;p&gt;
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).&amp;#160; 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.
&lt;/p&gt;
&lt;p&gt;
Durable, yes.&amp;#160; Scalable. No.
&lt;/p&gt;
&lt;h2&gt;Tell Me Why I Need It?
&lt;/h2&gt;
&lt;p&gt;
I can hear you now, you're probably thinking, &amp;quot;Hey that database table idea is
pretty slick.&amp;#160; I'm doing the same thing in my app and it works fine.&amp;#160; Why
do I need a whole new framework to do this?&amp;quot;&amp;#160; The problem that MassTransit
seeks to solve is that of scalability.&amp;#160; The database table for emails works well
if all you have to do is send emails.&amp;#160; The more messages you want to handle the
more database tables you have to add.&amp;#160; 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.&amp;#160; In other words for N types of
messages you have to do N things; and that's bad when you want to scale.
&lt;/p&gt;
&lt;h2&gt;Why MassTransit and not NServiceBus?
&lt;/h2&gt;
&lt;p&gt;
The reasons I chose to explore &lt;a href="http://code.google.com/p/masstransit/"&gt;MassTransit&lt;/a&gt; and
not &lt;a href="http://www.nservicebus.com/"&gt;NServiceBus&lt;/a&gt; are not scientific at all.&amp;#160;
You may not agree with them, and that is fine, but I'm providing them here so you
know why:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Familiar and Friendly Authors - Dru Seller is one of the nicest guys I met while in
Seattle at Alt.NET.&amp;#160; If I have questions or comments about MassTransit, I just
pick of the phone and give Dru a call.&amp;#160; Granted not all of you have that ability,
but again, I said these were my reasons.&amp;#160; If you are friends with Udi Dahan,
I'd strongly suggest you take a look at NServiceBus. 
&lt;/li&gt;
&lt;li&gt;
Familiar Commonality - MassTransit uses and integrates with other frameworks/libraries
that I use, most notably it's integration with Windsor/MicroKernel and secondly NHibernate. 
&lt;/li&gt;
&lt;li&gt;
Relatively Small - MassTransit is small, yet powerful, and covers the functionality
I need.&amp;#160; Being small and young, it is easier for me to go through the project
and it's history. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=988241d7-e4a0-4f01-8d3b-21094761ecc0" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,988241d7-e4a0-4f01-8d3b-21094761ecc0.aspx</comments>
      <category>Mass Transit</category>
    </item>
  </channel>
</rss>