<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andreas Öhlund</title>
	<atom:link href="http://andreasohlund.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://andreasohlund.net</link>
	<description>My thoughts on software development</description>
	<lastBuildDate>Tue, 31 Jan 2012 08:12:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>The difference between messages and messages</title>
		<link>http://andreasohlund.net/2012/01/31/the-difference-between-messages-and-messages/</link>
		<comments>http://andreasohlund.net/2012/01/31/the-difference-between-messages-and-messages/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 07:00:07 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=356</guid>
		<description><![CDATA[Ok that was a confusing title:) In NServiceBus we have 2 different types of messages and that usually confuses people. So lets take a look at the different types, what they should be used for and who should use them. The applicative message This is the type of message that most users think of when [...]]]></description>
			<content:encoded><![CDATA[<p>Ok that was a confusing title:)</p>
<p>In NServiceBus we have 2 different types of messages and that usually confuses people. So lets take a look at the different types, what they should be used for and who should use them.</p>
<h3>The applicative message</h3>
<p>This is the type of message that most users think of when we talk about messages. This is the <a href="http://eaipatterns.com/Message.html">message that you as a users of the framework will define in order to send data from a client to a server</a>. In NServiceBus this is either a C# class or interface inheriting from the IMessage marker interface and in 3.0 possibly <a href="http://nservicebus.com/UnobtrusiveMode.aspx">defined by a convention instead</a>. This is the message that you own version and control. Let&#8217;s call it a &#8220;message&#8221; going forwards. To send this message over the wire we need to serialize it to any of the supported formats, json, xml, protobuf etc. The serialized data is wrapped in an envelope that can be given the messaging system for store and forward transmission to its final destination. We call this a TransportMessage. You can send multiple of your applicative messages in the same go making them part of the same TransportMessage using the Bus.Send(object[] messages) signature.</p>
<h3>Transport messages, the workhorse of NServiceBus</h3>
<p>This is the other of the message types and is owned, controlled and versioned by NServiceBus. If you have read the EAI patterns book this would roughly translate to a <a href="http://eaipatterns.com/EnvelopeWrapper.html">envelope wrapper</a>. Other frameworks like Lokad.Cqrs just call them envelopes. The main purpose of this type of message is to carry the serialized payload across the wire but they also contains headers and infrastructure related information such as return address, time sent, id etc. TransportMessages is the physical unit that gets sent between a client and a server so If you look at messages in input queues, error or audit queues etc. it&#8217;s this kind of message you would see.</p>
<h3>Transport messages forms the unit of work</h3>
<p>It&#8217;s very important to understand that the unit of work when it comes to message processing is the Transport Message (TM). When NServiceBus picks up a TM from the input queue a transaction is created and all message handlers for the contained messages (remember it could be more than one) will execute in this transaction. If no exception is thrown the transaction will commit and the message will be removed. If any handler throws an error NServiceBus will retry a configurable number of time and then send the entire TM to the configured error queue. Most of the time messages will relate 1-1 to TM&#8217;s but you can use this feature if you want messages to be processed a whole inside a single transaction.</p>
<h3>Can there be empty transport messages?</h3>
<p>You as a user can&#8217;t send transport messages without contained messages but NServiceBus sends empty transport messages internally to control things like subscriptions, worker registration for the distributor etc. We call this special type if message a &#8220;ControlMessage&#8221; and they only contain headers.</p>
<p>Hopefully this post has shed some light when it comes to the different types of messages used in the NServiceBus lingo.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/31/the-difference-between-messages-and-messages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using RavenDB in NServiceBus &#8211; Connecting</title>
		<link>http://andreasohlund.net/2012/01/30/using-ravendb-in-nservicebus-connecting/</link>
		<comments>http://andreasohlund.net/2012/01/30/using-ravendb-in-nservicebus-connecting/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 07:00:26 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=316</guid>
		<description><![CDATA[In a previous post I talked about the different ways to make sure that you have a Raven server available in order for your NServiceBus endpoints to store their data. In this post we&#8217;ll look at the different options for connecting to that Raven server. To tell NServiceBus to use Raven for persistence is a easy [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous <a href="http://andreasohlund.net/2012/01/27/using-ravendb-in-nservicebus-installing/">post </a>I talked about the different ways to make sure that you have a Raven server available in order for your NServiceBus endpoints to store their data. In this post we&#8217;ll look at the different options for connecting to that Raven server.</p>
<p>To tell NServiceBus to use Raven for persistence is a easy as calling Configure.RavenPersistence(). This is the default configuration and it uses the following conventions:</p>
<ol>
<li>If no master node is configured it will assume that a Raven server is running at http://localhost:8080, the default url for RavenDB.</li>
<li>If a master node is configured the url used will be: http://{masternode}/:8080</li>
<li>If a connection string named &#8220;NServiceBus.Persistence&#8221; is found the value of the connectionString attribute will be used. This pretty much give you full control over which Raven server your endpoint will use</li>
</ol>
<div>If NServiceBus detects that any of the Raven related storage&#8217;s is used, Saga, Subscription, Timeouts, etc the above will be automatically configured for you. So in essense there should be no need for you to explicitly configure Raven unless you need to override the defaults.</div>
<h3>Overriding the defaults</h3>
<p>There are a few situations where the default behavior might not be good enough for you.</p>
<ul>
<li><strong>You want to use your own connection string</strong> &#8211; If you&#8217;re using Raven for your own data as well you might want to share connection string. You do this by using the Configure.RavenPersistence(string connectionString) signature. This tells NServiceBus to connection to the server specified in that string. The default connection string for RavenDB is &#8220;RavenDB&#8221;.</li>
<li><strong>You want to specify a explicit database name &#8211; </strong>If you want to control the database name in code instead of configuration you would use the  Configure.RavenPersistence(string connectionString, string databaseName) signature. This could be useful in multi tenant scenarios</li>
</ul>
<h3>What database will be used?</h3>
<p>After connecting to a Raven server we need to decide which actual database to use. Unless we find a default database specified in the connection string NServiceBus will use the <a href="http://andreasohlund.net/2012/01/27/convention-over-configuration-in-nservicebus-3-0/">endpoint name</a> as the database name. So if your endpoint is named &#8220;MyServer&#8221; the database name will be &#8220;MyServer&#8221;. Each endpoint will have a separate database unless you explicitly override using the connection string. RavenDB will automatically create the database if it doesn&#8217;t already exist.</p>
<p>A detailed explanation of the endpoint name concept can be found <a href="http://andreasohlund.net/2012/01/27/convention-over-configuration-in-nservicebus-3-0/">here</a>.</p>
<h3>Can I use the IDocumentStore used by NServiceBus for my own data?</h3>
<p>No the Raven client is merged and internalized into the NServiceBus assemblies so if you want to use Raven for your own purposes you need to reference the Raven client and setup your own document store.</p>
<h3>How do I look at the data?</h3>
<p>Just open a web browser and type the url if the Raven server, this will open up the <a href="http://ravendb.net/docs/studio">Raven DB management studio</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/30/using-ravendb-in-nservicebus-connecting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convention over configuration in NServiceBus 3.0</title>
		<link>http://andreasohlund.net/2012/01/27/convention-over-configuration-in-nservicebus-3-0/</link>
		<comments>http://andreasohlund.net/2012/01/27/convention-over-configuration-in-nservicebus-3-0/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 12:15:48 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=339</guid>
		<description><![CDATA[One of the key goals for NServiceBus 3.0 is to remove much of the need for configuration and there by improve the out of the box experience. In order to achieve this we have introduced the concept of a EndpointName that will be used to control our naming conventions. The endpoint name is the name of a [...]]]></description>
			<content:encoded><![CDATA[<p>One of the key goals for NServiceBus 3.0 is to remove much of the need for configuration and there by improve the out of the box experience. In order to achieve this we have introduced the concept of a <strong><em>EndpointName</em></strong> that will be used to control our naming conventions.</p>
<p>The endpoint name is the name of a <span style="text-decoration: underline;">individual endpoint</span> and must be unique across your solution. The only exception to this rule is when you are scaling out using the master node concept where the same logical endpoint would reside on many physical servers, more on that in a upcoming post.</p>
<h3>Conventions that use the endpoint name</h3>
<p>The following conventions use the endpoint name to configure various parts of NServiceBus. Note that the {masternode} will be localhost if not specified.</p>
<ul>
<li><strong>Local address &#8211; </strong>The local address (input queue) of your endpoint will be the {endpointname}</li>
<li><strong>Subscriptions &#8211; </strong>If you use the Msmq subscription storage the name of the queue used to store the subscribers will be {endpointname}.subscriptions</li>
<li><strong>Raven database name</strong> &#8211; The database name when storing data related to the endpoint will be {endpointname}</li>
<li><strong>Timeout manager address </strong>- The address of the timeout manager will be {endpointname}.timeouts@{masternode}</li>
<li><strong>Gateway input address </strong>- The address where the gateway will pickup outgoing messages will be {endpointname}.Gateway@{masternode}</li>
<li><strong>Gateway url </strong>- If you use the http/https channel the url that the gateway will listen to is defaulted to http(s)://localhost/{endpointname}</li>
<li><strong>Distributor input queue &#8211; </strong>The input queue of the distributor will be {endpointname}@{masternode}</li>
<li><strong>Distributor control queue - </strong>The control queue of the distributor will be {endpointname}.distributor.control@{masternode}</li>
<li><strong>Distributor storage queue - </strong>The local storage queue of the distributor will be {endpointname}.distributor.storage</li>
</ul>
<h3>How to specify the endpoint name</h3>
<p>There are multiple ways that you can define the endpoint name. Lets look at them one by one.</p>
<ul>
<li>If not specified by the user the namespace of the class implementing IConfigureThisEndpoint will be used as the endpoint name when running the NServiceBus host. If your project is called MyServer and the config is in the root this will result in the endpoint name &#8220;MyServer&#8221;. This is the recommended way to name a endpoint.</li>
<li>If not specified by the user when custom hosting NServiceBus the namespace of the class calling NServiceBus.Configure.With() will be used. For websites this will likely be the namespace of your global.asax.cs</li>
<li>You can set the endpoint name using the [EndpointName] attribute on your endpoint configuration.</li>
<li>You can implement the <a href="https://github.com/NServiceBus/NServiceBus/blob/master/src/hosting/NServiceBus.Hosting/Configuration/INameThisEndpoint.cs">INameThisEndpoint</a> interface on your endpoint config</li>
<li>If you specify a explicit service name when installing the NServiceBus host this will be used as endpoint name: /serviceName:&#8221;"MyEndpoint&#8221;</li>
<li>You can specify a endpoint name when running the NServiceBus host: /endpointName:&#8221;"MyEndpoint&#8221;</li>
</ul>
<div>As you can see there is lots of ways to do this. But if all the above is not enough you can define your own convention using:</div>
<div><em>Configure.DefineEndpointName(()=&gt;{&#8230;.})</em></div>
<h3>Upgrading from NServiceBus 2.6</h3>
<p>Users upgrading from 2.6 need to name their endpoint to the same name as their current input queue since there is no way to explicitly set the input queue in NServiceBus 3.0</p>
<h3>In closing</h3>
<p>Naming your endpoint will be a very important thing going forward and the framework will try to push you in that direction by not making it to easy for you to override. This will hope fully help us further improve our &#8220;convention over configuration&#8221; support make it even easier for you to build, deploy and run NServiceBus in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/27/convention-over-configuration-in-nservicebus-3-0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using RavenDB in NServiceBus &#8211; Installing</title>
		<link>http://andreasohlund.net/2012/01/27/using-ravendb-in-nservicebus-installing/</link>
		<comments>http://andreasohlund.net/2012/01/27/using-ravendb-in-nservicebus-installing/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 07:00:01 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=318</guid>
		<description><![CDATA[The default persistence in NServiceBus is as of version 3.0 RavenDB. The NServiceBus license permits the use of RavenDB for the storage need of your endpoint. This only includes NServiceBus related data like sagas, subscriptions etc. If you are storing application specific data in Raven you need to purchase a separate license. If you plan [...]]]></description>
			<content:encoded><![CDATA[<p>The default persistence in NServiceBus is as of version 3.0 RavenDB. The NServiceBus license permits the use of RavenDB for the storage need of your endpoint. This only includes NServiceBus related data like sagas, subscriptions etc. If you are storing application specific data in Raven you need to purchase a separate license.</p>
<p>If you plan to use the default storage you need to make sure that you have a Raven server running that your endpoint can connect to. There is two ways to set this up:</p>
<ol>
<li><a href="http://ravendb.net/download">Download</a> and install RavenDB your self</li>
<li>Let NServiceBus do it for you</li>
</ol>
<div>Use #1 if you&#8217;re already using raven or if you have other specific requirements for the installation.</div>
<h3>#2 Auto installation of RavenDB</h3>
<p>RavenDB is included with the NServiceBus binaries (not ilmerged) and we have a <a href="http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/">infrastructure installer</a> that will make sure that Raven is installed on the local machine when the installers are <a href="http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/">invoked</a>.</p>
<p>The install is only performed if the following is true:</p>
<ol>
<li>Raven persistence is configured for the endpoint</li>
<li>A custom connection string is not specified by the user</li>
<li>The current endpoint has no master node specified</li>
<li>Port 8080 is available</li>
<li>Raven is not already installed</li>
<li>The install is done using the explicit /installInfrastructure</li>
</ol>
<div>#3 deserves a little more explanation. Having a master node defined tells NServiceBus that all data will be stored on the that server instead. This means that we expect the Raven server to be running on that remote machine and not the local machine where you&#8217;re running the install.</div>
<div>For instructions on how to administrate and operate a Raven server please see the documentation for RavenDB &#8211;  <a href="http://ravendb.net/docs/server/administration">http://ravendb.net/docs/server/administration</a></div>
<div>That is all there is to it!</div>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/27/using-ravendb-in-nservicebus-installing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installers in NServiceBus 3.0</title>
		<link>http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/</link>
		<comments>http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 09:21:18 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=304</guid>
		<description><![CDATA[In 3.0 we introduced the concept of installers to make sure that both infrastructure  and endpoint specific artifact installed and configured automatically for you if needed. The installers comes in two flavors, infrastructure installers and regular installers. Infrastructure installers are used for things that are not specific to a given endpoint eg. RavenDB, MSMQ. Regular [...]]]></description>
			<content:encoded><![CDATA[<p>In 3.0 we introduced the concept of installers to make sure that both infrastructure  and endpoint specific artifact installed and configured automatically for you if needed.</p>
<p>The installers comes in two flavors, infrastructure installers and regular installers. Infrastructure installers are used for things that are not specific to a given endpoint eg. RavenDB, MSMQ. Regular installers are focused on setting up things that the current endpoint is depending on eg. queues, folders, databases etc. Infrastructure installers are always invoked before regular installers. Although the installers are mainly used internally you could use the for your own purposed as well. Perhaps you need to make sure folders are created, database scripts invoked etc etc.</p>
<p>To create your own installer is as easy as implementing the <a href="https://github.com/NServiceBus/NServiceBus/blob/master/src/installation/NServiceBus.Installation/INeedToInstallInfrastructure.cs">INeedToInstallInfrastructure&lt;T&gt;</a> interface. The generic parameter gives you a way to restrict your installer to a specific platform. Currently this is either Windows or Azure. If you don&#8217;t care about the environment use the <a href="https://github.com/NServiceBus/NServiceBus/blob/master/src/installation/NServiceBus.Installation/INeedToInstallInfrastructure.cs">INeedToInstallInfrastructure</a> interface instead. To create a regular installer you just implement the <a href="https://github.com/NServiceBus/NServiceBus/blob/master/src/installation/NServiceBus.Installation/INeedToInstallSomething.cs">INeedToInstallSomething&lt;T&gt;</a> interface again using the T to restrict it to a specific environment.</p>
<p>NServiceBus will scan the assemblies in the runtime directory for installers so you don&#8217;t need any code to register them.</p>
<h3>When are they invoked?</h3>
<p>When using the NServiceBus host installers are invoked as follows:</p>
<table width="580" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="222"></td>
<td colspan="2" valign="top" width="358">
<p align="center"><strong>Installers invoked</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="222">
<p align="center"><strong>Command Line parameters</strong></p>
</td>
<td valign="top" width="188">
<p align="center"><strong>Infrastructure</strong></p>
</td>
<td valign="top" width="170">
<p style="text-align: center;"><strong>Regular</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="222">/install NServiceBus.Production</td>
<td valign="top" width="188">
<p align="center">√</p>
</td>
<td valign="top" width="170">                    √</td>
</tr>
<tr>
<td valign="top" width="222">NServiceBus.Production</td>
<td valign="top" width="188">
<p align="center"><strong>×</strong></p>
</td>
<td valign="top" width="170">
<p align="center"><strong>×</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="222">/install NServiceBus.Integration</td>
<td valign="top" width="188">
<p align="center">√</p>
</td>
<td valign="top" width="170">
<p align="center">√</p>
</td>
</tr>
<tr>
<td valign="top" width="222">NServiceBus.Integration</td>
<td valign="top" width="188">
<p align="center"><strong>×</strong></p>
</td>
<td valign="top" width="170">
<p align="center">√</p>
</td>
</tr>
<tr>
<td valign="top" width="222">/install NServiceBus.Lite</td>
<td valign="top" width="188">
<p align="center">√<strong></strong></p>
</td>
<td valign="top" width="170">
<p align="center">√</p>
</td>
</tr>
<tr>
<td valign="top" width="222">NServiceBus.Lite</td>
<td valign="top" width="188">
<p align="center"><strong>×</strong></p>
</td>
<td valign="top" width="170">
<p align="center">√</p>
</td>
</tr>
</tbody>
</table>
<p>As you can see the installers are controlled by both the /install command line option to the host and the current profile used. You can of course implement your own profile if you have other requirements.</p>
<p>When self hosting NServiceBus you have to invoke the installers manually using:</p>
<div id="gist-1681872" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">Configure</span><span class="p">.</span><span class="n">Instance</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">ForInstallationOn</span><span class="p">&lt;</span><span class="n">NServiceBus</span><span class="p">.</span><span class="n">Installation</span><span class="p">.</span><span class="n">Environments</span><span class="p">.</span><span class="n">Windows</span><span class="p">&gt;()</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">Install</span><span class="p">()</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1681872/183de1ddd75bb26d6e5c81c13d96581f4e428afd/RunCustomInstall.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1681872#file_run_custom_install.cs" style="float:right;margin-right:10px;color:#666">RunCustomInstall.cs</a>
            <a href="https://gist.github.com/1681872">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>A full example can be found <a href="https://github.com/NServiceBus/NServiceBus/blob/master/Samples/AsyncPages/WebApplication1/Global.asax.cs">here</a>.</p>
<p>Finally there is one final way to run the infrastructure installers. If you invoke the host with the /installInfrastructure flag the host will run only the infrastructure installers for you without requiring you to configure anything. This can be useful when you setup a new server or a developer machine since that verifies and installs the required infrastructure for NServiceBus to run. The RunMeFirst.bat included in the download is doing just that.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t assume message ordering</title>
		<link>http://andreasohlund.net/2012/01/18/dont-assume-message-ordering/</link>
		<comments>http://andreasohlund.net/2012/01/18/dont-assume-message-ordering/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 14:45:43 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[EDA]]></category>
		<category><![CDATA[Guidelines]]></category>
		<category><![CDATA[Messaging]]></category>
		<category><![CDATA[Queuing]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=301</guid>
		<description><![CDATA[On my travels I often see people getting into trouble by assuming that messages will be processed in the same order as they are being sent. If the there was a list of fallacies for asynchronous messaging this one would be: Messages will always be processed in order The reason why this is not true mainly comes from the [...]]]></description>
			<content:encoded><![CDATA[<p>On my travels I often see people getting into trouble by assuming that messages will be processed in the same order as they are being sent. If the there was a list of fallacies for asynchronous messaging this one would be:</p>
<blockquote><p>Messages will always be processed in order</p></blockquote>
<p>The reason why this is not true mainly comes from the fallacy that the network is reliable. This turns out, often painfully, to not be true and usually leads us to use message queuing systems like MSMQ, RabbitMQ, ActiveMQ, etc.</p>
<p><img class="alignright" title="Highway" src="http://cdn5.wn.com/pd/64/97/39a31f841718c80fc233cf73aa01_grande.jpg" alt="" width="468" height="351" />Queuing systems helps us mitigate the &#8220;network is reliable&#8221; fallacy by providing us with store and forward capabilities. This basically means that a sent message will be stored locally until the infrastructure can transfer the message safely to the recipient. To do all this in a performant and scalable way queuing systems usually won&#8217;t supports ordered delivery since that drives the complexity up making the former hard to achieve. You can think of this like a multi lane highway, some cars will travel faster than others, due to size, speed,number of stops,etc. This leads to messages overtaking each other and there for reach their destination in random order. Even if they do arrive in order there can be multiple concurrent threads processing them which leads to even more rearrangement.</p>
<h3>But every thing seems to run fine on my machine?</h3>
<p>This is what make the whole thing so tricky. Systems under light load will most of the time process messages in order. This means that you will only see this happening when your system is under heavy load making it very hard to debug.</p>
<h3>But I use one thread and have a queuing system that guarantees order?</h3>
<p>Yes running in this mode will solve give you ordering at the infrastructure level. But unfortunately this is not enough. Communication frameworks like NServiceBus will manage exceptions for you by doing a few retries and  then moving the message to a error queue. This means that a message can be retried from the error queue days after it arrived to its original destination. While this is happening you don&#8217;t want your entire system grind to a halt while that message is waiting for someone to issue a retry. This means that even though the infrastructure might support ordered delivery, messages can still be processed out of order at the application level.</p>
<h3>So what should we do then?</h3>
<p>There is unfortunately no silver bullet available that will solve all this for you. First of all you need to make sure that you never write code that assumes messages to arrive in a certain order, you can&#8217;t even assume that they will arrive at all .This leads you to write explicit code to make sure that your application behaves consistently in these situations. This is a good thing!</p>
<p>You can solve this in a few ways, some times the solution is to anchor the message in time so that the receiver can make correct decisions. Publishing price updates is a good example where having a ValidFrom &#8211; ValidTo will make processing order irrelevant. Another common way is to use <a href="http://nservicebus.com/Sagas.aspx">sagas </a>as a way to ensure that message ordering won&#8217;t matter. I won&#8217;t go into the details but if you&#8217;re interested I&#8217;ve done a few talks on this subject:</p>
<p><a href="http://andreasohlund.net/2011/03/12/notes-from-my-e-van-talk-on-sagas/">http://andreasohlund.net/2011/03/12/notes-from-my-e-van-talk-on-sagas/</a></p>
<p><a href="http://skillsmatter.com/podcast/open-source-dot-net/reliable-integrations-nservicebus">http://skillsmatter.com/podcast/open-source-dot-net/reliable-integrations-nservicebus</a></p>
<h3>In closing</h3>
<p>Repeat after me: <strong><span style="text-decoration: underline;">Don&#8217;t assume message ordering when building a message based system</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2012/01/18/dont-assume-message-ordering/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Support for running NServiceBus in Unobtrusive mode</title>
		<link>http://andreasohlund.net/2011/12/15/support-for-running-nservicebus-in-unobtrusive-mode/</link>
		<comments>http://andreasohlund.net/2011/12/15/support-for-running-nservicebus-in-unobtrusive-mode/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 19:01:52 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=291</guid>
		<description><![CDATA[When using NServiceBus you define your message contracts using plain C# classes or interfaces. So far so good. In order for NServiceBus to find those classes when scanning your assemblies you need to mark them with the special IMessage interface. This essentially tells us that &#8220;hey this is a message definition, please use it&#8221;. This [...]]]></description>
			<content:encoded><![CDATA[<p>When using NServiceBus you define your message contracts using plain C# classes or interfaces. So far so good. In order for NServiceBus to find those classes when scanning your assemblies you need to mark them with the special <em>IMessage </em>interface. This essentially tells us that &#8220;hey this is a message definition, please use it&#8221;. This might seem like a small thing but now you&#8217;re coupling your message contracts to a NServiceBus assembly since you need to reference the NServiceBus.dll in order get access to the interface. This dependency can cause problems if you have different services that run different versions of NServiceBus. I&#8217;m not going into the details since Jonathan Oliver has a <a href="http://blog.jonathanoliver.com/2010/09/nservicebus-distributing-event-schemacontract/">great write up on this very subject</a>.</p>
<p>This is not a big deal for commands because they are always used with in the boundary of a single service and it&#8217;s fair to require a service to use the same version of NServiceBus. But when it comes to events this becomes more of a problem since requiring all of your services to use the same version of NServiceBus and there by forcing them to upgrade NServiceBus all at once is not an ideal thing.</p>
<h2>The solution</h2>
<p>There are a couple of ways you can solve this. Jonathan mentions a few in his post. NServiceBus 3.0 has a few changes that will help you further.</p>
<ol>
<li>Not bumping the assembly version for non-breaking changes. Following the <a href="http://semver.org">semver.org</a> semantics we only change our assembly version when we make changes that are not backwards compatible. This mean that 3.0.1 and 3.0.X will have this same assembly version, fileversion is of course changed for every release/build. This means that as long as you do a nuget update with the -safe flag your service contracts will stay compatible.</li>
<li>Support for running in what we call &#8220;Unobtrusive&#8221; mode. Running in unobtrusive mode removes the need for you to reference any NServiceBus assemblies from your own message assemblies. This obviously removes the problem altogether.</li>
</ol>
<h2>Unobtrusive mode</h2>
<p>This new feature in NServiceBus 3.0 allows you to pass in your own conventions to determine which types are message definitions instead of using the <em>IMessage</em> interface.</p>
<p>Below is a snippet that shows how to define those conventions:</p>
<div id="gist-1482280" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;<span class="n">Configure</span><span class="p">.</span><span class="n">With</span><span class="p">()</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">DefiningCommandsAs</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span> <span class="p">!=</span> <span class="k">null</span> <span class="p">&amp;&amp;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span><span class="p">.</span><span class="n">EndsWith</span><span class="p">(</span><span class="s">&quot;Commands&quot;</span><span class="p">))</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">DefiningEventsAs</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span> <span class="p">!=</span> <span class="k">null</span> <span class="p">&amp;&amp;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span><span class="p">.</span><span class="n">EndsWith</span><span class="p">(</span><span class="s">&quot;Events&quot;</span><span class="p">))</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">DefiningMessagesAs</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span> <span class="p">!=</span> <span class="k">null</span> <span class="p">&amp;&amp;</span> <span class="n">t</span><span class="p">.</span><span class="n">Namespace</span><span class="p">.</span><span class="n">EndsWith</span><span class="p">(</span><span class="s">&quot;Messages&quot;</span><span class="p">))</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">DefiningEncryptedPropertiesAs</span><span class="p">(</span><span class="n">p</span> <span class="p">=&gt;</span> <span class="n">p</span><span class="p">.</span><span class="n">Name</span><span class="p">.</span><span class="n">StartsWith</span><span class="p">(</span><span class="s">&quot;Encrypted&quot;</span><span class="p">));</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1482280/2c1487e16742f7a183c97600916c69ad77a7c4bc/Unobtrusive-config.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1482280#file_unobtrusive_config.cs" style="float:right;margin-right:10px;color:#666">Unobtrusive-config.cs</a>
            <a href="https://gist.github.com/1482280">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The code above tells NServiceBus to treat all interfaces/classes with a namespace that ends with &#8220;Messages&#8221; as messages. As you see you can also specify conventions for the new <a href="http://andreasohlund.net/2011/12/08/introducing-ievent-and-icommand/">ICommand and IEvent feature</a> as well.</p>
<p>NServiceBus supports property level encryption by using a special <em>WireEncryptedString</em> property and the last line in the snippet is the unobtrusive way to accomplish that encryption.</p>
<p>That is pretty much all there is to it.</p>
<p>A working sample can be found <a href="https://github.com/NServiceBus/NServiceBus/tree/master/Samples/Unobtrusive">here</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2011/12/15/support-for-running-nservicebus-in-unobtrusive-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recording of my talk on the new features in NServiceBus 3.0</title>
		<link>http://andreasohlund.net/2011/12/09/recording-of-my-talk-on-the-new-features-in-nservicebus-3-0/</link>
		<comments>http://andreasohlund.net/2011/12/09/recording-of-my-talk-on-the-new-features-in-nservicebus-3-0/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 05:26:41 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Presenting]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=282</guid>
		<description><![CDATA[Last night I did a talk on the new features in the upcoming release of NServiceBus. The session was recorded and can be found here: http://skillsmatter.com/podcast/open-source-dot-net/nservicebus-3/wd-3134 Slides can be found here: http://www.slideshare.net/andreasohlund/new-and-shiny-things-in-n-service-bus-30 Thanks to Skills Matter doing for recording and for being awesome in general.]]></description>
			<content:encoded><![CDATA[<p>Last night I did a talk on the new features in the upcoming release of NServiceBus.</p>
<p>The session was recorded and can be found here:</p>
<p><a href="http://skillsmatter.com/podcast/open-source-dot-net/nservicebus-3/wd-3134">http://skillsmatter.com/podcast/open-source-dot-net/nservicebus-3/wd-3134</a></p>
<p>Slides can be found here:</p>
<p><a href="http://www.slideshare.net/andreasohlund/new-and-shiny-things-in-n-service-bus-30">http://www.slideshare.net/andreasohlund/new-and-shiny-things-in-n-service-bus-30</a></p>
<p>Thanks to <a href="http://skillsmatter.com">Skills Matter</a> doing for recording and for being awesome in general.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2011/12/09/recording-of-my-talk-on-the-new-features-in-nservicebus-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing IEvent and ICommand</title>
		<link>http://andreasohlund.net/2011/12/08/introducing-ievent-and-icommand/</link>
		<comments>http://andreasohlund.net/2011/12/08/introducing-ievent-and-icommand/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 13:09:58 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=279</guid>
		<description><![CDATA[One of the new features in NServiceBus 3.0 is the introduction of two new message interfaces, IEvent and ICommand. The purpose is to capture more of the intent of the messages that you as a user are defining. This will help NServiceBus to enforce messaging best practices and stop you from doing crazy things:) Messages implementing ICommand [...]]]></description>
			<content:encoded><![CDATA[<p>One of the new features in NServiceBus 3.0 is the introduction of two new message interfaces, IEvent and ICommand. The purpose is to capture more of the intent of the messages that you as a user are defining. This will help NServiceBus to enforce messaging best practices and stop you from doing crazy things:)</p>
<p><span class="Apple-style-span" style="font-size: 20px; font-weight: bold;">Messages implementing ICommand</span></p>
<ul>
<li>Is not allowed to be published since all commands should have one logical owner and should be sent to the endpoint responsible for processing</li>
<li>Can&#8217;t be subscribed and unsubscribed to</li>
<li>Can&#8217;t implement IEvent</li>
</ul>
<div>
<h2>Messages implementing IEvent</h2>
<ul>
<li>Can be published</li>
<li>Can be subscribed and unsubscribed to</li>
<li>Can&#8217;t be sent using Bus.Send() since all events should be Published</li>
<li>Can&#8217;t implement ICommand</li>
<li>Can&#8217;t be sent using the gateway, ie bus.SendToSites()</li>
</ul>
<div>So please go ahead and use those additional interfaces if you wan&#8217;t NServiceBus to help you fall into the pit of success.</div>
<div>Please add a comment if you have for additional checks that we should do!</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2011/12/08/introducing-ievent-and-icommand/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>One way/Send only endpoints</title>
		<link>http://andreasohlund.net/2011/12/02/one-waysend-only-endpoints/</link>
		<comments>http://andreasohlund.net/2011/12/02/one-waysend-only-endpoints/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 07:00:47 +0000</pubDate>
		<dc:creator>Andreas Öhlund</dc:creator>
				<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://andreasohlund.net/?p=269</guid>
		<description><![CDATA[The equivalent to the one way bus in Rhino Service Bus is what we in NServiceBus call &#8220;Send only mode&#8221;.  In short you would use this in endpoints who&#8217;s only purpose is  sending messages, websites are often a good example of send only endpoints. I&#8217;ve blogged about it a while back but the syntax has changed slightly since then. This time [...]]]></description>
			<content:encoded><![CDATA[<p>The equivalent to the <a href="http://ayende.com/blog/140289/setting-up-a-rhino-service-bus-application-part-iindash-one-way-bus">one way bus in Rhino Service Bus</a> is what we in NServiceBus call &#8220;Send only mode&#8221;.  In short you would use this in endpoints who&#8217;s only purpose is  sending messages, websites are often a good example of send only endpoints. I&#8217;ve <a href="http://andreasohlund.net/2010/08/10/send-only-endpoints/">blogged about it </a>a while back but the syntax has changed slightly since then. This time we&#8217;ll take closer look at the code needed to start in send only mode.</p>
<div id="gist-1417373" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">var</span> <span class="n">bus</span> <span class="p">=</span> <span class="n">Configure</span><span class="p">.</span><span class="n">With</span><span class="p">()</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">DefaultBuilder</span><span class="p">()</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">XmlSerializer</span><span class="p">()</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">MsmqTransport</span><span class="p">()</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">UnicastBus</span><span class="p">()</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">SendOnly</span><span class="p">();</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="n">bus</span><span class="p">.</span><span class="n">Send</span><span class="p">(</span><span class="k">new</span> <span class="n">TestMessage</span><span class="p">());</span></div><div class='line' id='LC9'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1417373/4601d2e83bfc45f3239c4ae0cf5a4c72882539fc/SendOnly.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1417373#file_send_only.cs" style="float:right;margin-right:10px;color:#666">SendOnly.cs</a>
            <a href="https://gist.github.com/1417373">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The only configuration needed when running in this mode is the destination of the messages you&#8217;re sending, you can do this either <a href="http://nservicebus.com/docs/Samples/FullDuplex.aspx">inline or through configuration</a>.</p>
<p>A working sample can be found <a href="https://github.com/NServiceBus/NServiceBus/tree/develop/Samples/SendOnlyEndpoint">here</a>.</p>
<p>That&#8217;s really all there is to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreasohlund.net/2011/12/02/one-waysend-only-endpoints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

