<?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>The Inquisitive Coder - Davy Brion&#039;s Blog &#187; nservicebus</title>
	<atom:link href="http://davybrion.com/blog/category/nservicebus/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Thu, 29 Jul 2010 20:51:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MSDTC Woes With NServiceBus And NHibernate</title>
		<link>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/</link>
		<comments>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 10:52:16 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
				<category><![CDATA[.NET bugs]]></category>
		<category><![CDATA[MSDTC]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[nservicebus]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/</guid>
		<description><![CDATA[I’ve spent about 3 days trying to get something working that should’ve just worked.&#160; I basically wanted some .NET code to use a distributed transaction to update some data in a database, and then publish a message on the service bus.&#160; I want to do this in a distributed transaction because if something goes wrong, [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve spent about 3 days trying to get something working that should’ve just worked.&#160; I basically wanted some .NET code to use a distributed transaction to update some data in a database, and then publish a message on the service bus.&#160; I want to do this in a distributed transaction because if something goes wrong, i want to roll back both transactions (the database change and the published message).&#160; Normally, this should just work if you have MS DTC configured correctly.&#160; On my machine, i enabled Network DTC Access, and allowed outbound transaction communication.&#160; On the database server, Network DTC Access was already enabled and both outbound and inbound communication was allowed.&#160; </p>
<p>Now the thing is, i’d either expect DTC to fail outright or to just work.&#160; But it shouldn’t fail in one situation, and work in another.&#160; On my machine, it failed in the following situation (which i’ll further refer to as Situation A):</p>
<ol>
<li>open a transaction scope </li>
<li>open an nhibernate session </li>
<li>hit the db </li>
<li>publish a message through nservicebus </li>
<li>close the nhibernate session </li>
<li>complete and close the transaction scope </li>
</ol>
<p>Step 4 and 5 could be switched around but it didn’t make a difference.&#160; In Situation A, i always got a TransactionManagerCommunicationException with the following message:</p>
<blockquote><p>Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.</p>
</blockquote>
<p>Everyone who’s worked with MSDTC before probably knows that exception since it usually takes some fiddling with the settings to make things work.&#160; The thing is, i was pretty sure that my settings, as well as the ones on the database server were correct.&#160; Unfortunately, DTCPing didn’t confirm that since that too failed.</p>
<p>However, i also tried the following sequence of events (Situation B):</p>
<ol>
<li>open a transaction scope </li>
<li>open an nhibernate session </li>
<li>publish a message </li>
<li>hit the db </li>
<li>close the nhibernate session </li>
<li>complete and close the transaction scope </li>
</ol>
<p>And guess what.&#160; That actually worked.&#160; With full DTC transaction semantics.&#160; The DTC statistics on the server confirmed that it was indeed using a DTC transaction, and if i made the code fail with an exception both the database action and the published message were correctly rolled back.</p>
<p>So the question is: why on earth does it only work when i publish a message before i hit the db?</p>
<p>During my investigation i noticed that in Situation A, the internal transaction that the transaction scope was using was a SqlDelegatedTransaction.&#160; Which, if i’m not mistaken is an LTM transaction.&#160; When trying to send a message to a message queue, the transaction manager tries to promote the current transaction to an OletxCommittableTransaction since the OleTx transaction protocol is required when using MSMQ (it doesn’t support LTM transactions).&#160; For some reason, promoting the SqlDelegatedTransaction to a full DTC (OleTx) transaction fails on my machine.</p>
<p>In Situation B, the internal transaction is promoted to an OletxCommittableTransaction as soon as you try to send the message to a message queue.&#160; Once it’s time to hit the DB, NHibernate nicely works together with the OletxCommittableTransaction and everything just works. </p>
<p>Now, i have no idea on earth why promotion of a SqlDelegatedTransaction fails, but after a long number of attempts and experiments to get it working correctly, i sorta gave up and figured i’d have to resort to a hack.&#160; What i basically needed was for the transaction scope’s internal transaction to automatically be promoted to an OletxCommittableTransaction <em>before<strong> </strong></em>i’d hit the database and without having to publish a dummy message at the beginning of the transaction.</p>
<p>I found one way of doing this which, while being a huge hack, is still relatively clean i think.&#160; I wrote the following class:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">DummyEnlistmentNotification</span> : <span style="color: #2b91af">IEnlistmentNotification</span></p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">Guid</span> Id = <span style="color: blue">new</span> <span style="color: #2b91af">Guid</span>(<span style="color: #a31515">&quot;E2D35055-4187-4ff5-82A1-F1F161A008D0&quot;</span>);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> Prepare(<span style="color: #2b91af">PreparingEnlistment</span> preparingEnlistment)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; preparingEnlistment.Prepared();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> Commit(<span style="color: #2b91af">Enlistment</span> enlistment)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> Rollback(<span style="color: #2b91af">Enlistment</span> enlistment)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> InDoubt(<span style="color: #2b91af">Enlistment</span> enlistment)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
</p></div>
<p>&#160;</p>
<p>Then, right after opening the transaction scope and before doing anything else, i do this:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: #2b91af">Transaction</span>.Current.EnlistDurable(<span style="color: #2b91af">DummyEnlistmentNotification</span>.Id, <span style="color: blue">new</span> <span style="color: #2b91af">DummyEnlistmentNotification</span>(), <span style="color: #2b91af">EnlistmentOptions</span>.None);</p>
</p></div>
<p>&#160;</p>
<p>This basically tells the System.Transactions infrastructure that we’re adding our own Resource Manager to the current transaction.&#160; And because it’s a durable Resource Manager, it now automatically promotes the internal transaction to an OletxCommittableTransaction and everything just works.&#160; While our Resource Manager participates in the 2-phase-commit process, it doesn’t actually do anything.&#160; It’s sole purpose is to force the creation of an OletxCommittableTransaction.</p>
<p>Like i said, it’s a hack but it’s still relatively clean.&#160; I still have no idea why i needed to resort to this hack though… If anyone can shed some light on this, i’d highly appreciate it <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also, if you ever want to learn more about transactions in .NET or distributed transactions in particular, you really need to check out <a href="http://www.codeproject.com/KB/WCF/NETTx.aspx" target="_blank">this article</a>.&#160; Without it, i probably wouldn’t have figured out what to do <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Avoiding Memory Leaks With NServiceBus And Your Own Castle Windsor Instance</title>
		<link>http://davybrion.com/blog/2010/02/avoiding-memory-leaks-with-nservicebus-and-your-own-castle-windsor-instance/</link>
		<comments>http://davybrion.com/blog/2010/02/avoiding-memory-leaks-with-nservicebus-and-your-own-castle-windsor-instance/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:42:55 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
				<category><![CDATA[Castle Windsor]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[nservicebus]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=2268</guid>
		<description><![CDATA[If you’re using NServiceBus together with your own instance of Castle Windsor, there is one thing you really need to look out for.&#160; NServiceBus was originally developed with Spring.NET as its IoC container, but it’s been changed to support multiple containers in a similar manner as Agatha does it.&#160; Agatha however, was originally developed with [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re using NServiceBus together with your own instance of Castle Windsor, there is one thing you really need to look out for.&#160; NServiceBus was originally developed with Spring.NET as its IoC container, but it’s been changed to support multiple containers in a similar manner as <a href="http://davybrion.com/blog/2009/11/integrating-your-ioc-container-with-agatha/" target="_blank">Agatha does it</a>.&#160; Agatha however, was originally developed with Castle Windsor as its IoC container, and as such is well aware of Windsor’s <a href="http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/" target="_blank">need to explicitly release resolved components</a>.&#160;&#160; NServiceBus unfortunately was <a href="http://tech.groups.yahoo.com/group/nservicebus/message/5376" target="_blank">not aware of this need</a>, and a workaround that they have introduced is to set Windsor’s ReleasePolicy to the NoTrackingReleasePolicy (which doesn’t hold any instances in memory, but doesn’t provide any cleanup either) if you configure NServiceBus to use <em>its own instance of </em>Castle Windsor.&#160; However, if you’re integrating NServiceBus into a project that is already using Castle Windsor, then you probably want NServiceBus to use <em>your instance</em> of Castle Windsor.</p>
<p>And that is when problems might appear.&#160; If you’re using Castle Windsor with the default ReleasePolicy (which is the LifecycledComponentsReleasePolicy) then each resolved transient instance will be stored in memory by that policy until the instance is explicitly released.&#160; The benefit of this policy is that the container can automatically dispose any disposable transient dependency of a resolved component.&#160; In my case, i’ve come to rely on that feature to achieve deterministic disposal behavior throughout my code base.&#160; </p>
<p>Now, when you configure NServiceBus and pass it your instance of Castle Windsor, it obviously doesn’t change the ReleasePolicy like it does when it creates its own instance of Castle Windsor.&#160;&#160; This is good because changing the policy of a passed in container would almost certainly have a huge behavioral implication for the application and such an action would be unacceptable when integrating a new framework into your project.&#160;&#160; But since NServiceBus doesn’t have the notion of needing to release resolved components, every single transient instance it resolves through <em>your</em> container will be stored in memory until the application’s process is terminated.&#160; Which means that you’ll leak instances of the following types <em>for each message</em> that your system needs to handle:</p>
<ul>
<li>NServiceBus.Grid.MessageHandlers.GridInterceptingMessageHandler </li>
<li>NServiceBus.Sagas.Impl.SagaMessageHandler </li>
<li>Your own MessageHandlers (and their transient dependencies as well) </li>
</ul>
<p>If your MessageHandlers don’t have dependencies (highly unlikely if you’re already using an IOC container) then you’d still have 3 leaking instances per incoming message.&#160; Add the number of transient dependencies of any handler to that and the number of leaking instances can increase dramatically.</p>
<p>First of all, if you do not depend on Windsor’s default ReleasePolicy’s behavior, then the easiest way to avoid this problem is definitely to set the container’s ReleasePolicy to the NoTrackingReleasePolicy like NServiceBus does itself when it’s configuring itself with a new instance of the container.</p>
<p>If you do depend on it, and you don’t want leaking instances that hang around forever, then the approach listed below is one way to solve this problem.&#160; There are probably other solutions available, and while the approach listed below can definitely be considered to be a HACK, i do think it’s the best solution to this particular problem.</p>
<p>Because we don’t want to change anything about the way that we’re already using the container, we just need to make sure that NServiceBus’ usage of the container doesn’t conflict with ours.&#160; That basically means that we need to make sure that the components that it resolves should not be tracked by the container.&#160;&#160; There are 2 kinds of components that NServiceBus will resolve during normal operation:</p>
<ol>
<li>Its own components that it needs to implement the features it offers you </li>
<li>Your message handlers that you need to handle incoming messages </li>
</ol>
<p>The first category is easy to exclude from Windsor’s tracking behavior.&#160; We can simply create our own ReleasePolicy which extends the default ReleasePolicy, and make sure that any instances of an NServiceBus-type are no longer tracked by the container:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">MyReleasePolicy</span> : Castle.MicroKernel.Releasers.<span style="color: #2b91af">LifecycledComponentsReleasePolicy</span></p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Track(<span style="color: blue">object</span> instance, Castle.MicroKernel.<span style="color: #2b91af">Burden</span> burden)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (!instance.GetType().FullName.StartsWith(<span style="color: #a31515">&quot;NServiceBus&quot;</span>))</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">base</span>.Track(instance, burden);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
</p></div>
<p>&#160;</p>
<p>Then you need to set this release policy somewhere in your application’s startup routine:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IoC</span>.Container.Kernel.ReleasePolicy = <span style="color: blue">new</span> <span style="color: #2b91af">MyReleasePolicy</span>();</p>
</p></div>
<p>&#160;</p>
<p>(in this case, IoC.Container returns an IWindsorContainer instance)</p>
<p>This will make sure that no instances of NServiceBus-types will ever leak in the container.&#160; But now we still have to deal with our message handlers.&#160; The solution to making sure they are not disposed is not the cleanest out there but hey, it works.&#160; I basically introduced a base class that all my message handlers will need to inherit from, with the following implementation in the Handle method:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">class</span> <span style="color: #2b91af">MessageHandler</span>&lt;TMessage&gt; : <span style="color: #2b91af">IMessageHandler</span>&lt;TMessage&gt; <span style="color: blue">where</span> TMessage : <span style="color: #2b91af">IMessage</span></p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> Handle(TMessage message)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">try</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Process(message);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">finally</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// ugly as hell, but we need this until NSB releases its resolved components</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IoC</span>.Container.Release(<span style="color: blue">this</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">protected</span> <span style="color: blue">abstract</span> <span style="color: blue">void</span> Process(TMessage message);</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
</p></div>
<p>&#160;</p>
<p>Uh oh… i just felt a great disturbance in the Force, as if tens of voices suddenly cried out in terror about my direct usage of the IoC container in a component!</p>
<p>Conceptually, this is wrong on many levels.&#160; Then again, this makes sure that the message handlers (and their dependencies) that are resolved by NServiceBus will always be guaranteed to be released by the comtainer.&#160; It might not be nice, but it avoids the memory leak and it doesn’t force me to change <em>my other code</em>.</p>
<p>And once NServiceBus is modified to release the components it resolves (if it’s ever modified that is…) i only need to get rid of my custom policy and the try/finally block.&#160; Unfortunately, my existing message handlers will then all implement the Process method instead of the Handle method but that is quickly fixed with a simple rename-refactoring.</p>
<p>Even though this is a pretty big hack (IMHO), at least its impact on the code is minimal… it will be easy to get rid of once the real problem is solved in NSB, and there are no real downsides to this that i can think of at the moment. </p>
]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2010/02/avoiding-memory-leaks-with-nservicebus-and-your-own-castle-windsor-instance/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Agatha Vs NServiceBus?</title>
		<link>http://davybrion.com/blog/2010/01/agatha-vs-nservicebus/</link>
		<comments>http://davybrion.com/blog/2010/01/agatha-vs-nservicebus/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 20:50:51 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
				<category><![CDATA[agatha]]></category>
		<category><![CDATA[nservicebus]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/2010/01/agatha-vs-nservicebus/</guid>
		<description><![CDATA[Ever since i open sourced Agatha, i’ve gotten questions from people who are wondering whether they should use Agatha or NServiceBus.&#160; I’ve also gotten questions about things that people wanted to do with Agatha but that aren’t really supported.&#160; And i’ve also noticed that people were coming to my site with search keywords like “agatha [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since i open sourced <a href="http://code.google.com/p/agatha-rrsl/" target="_blank">Agatha</a>, i’ve gotten questions from people who are wondering whether they should use Agatha or <a href="http://nservicebus.com/" target="_blank">NServiceBus</a>.&#160; I’ve also gotten questions about things that people wanted to do with Agatha but that aren’t really supported.&#160; And i’ve also noticed that people were coming to my site with search keywords like “agatha vs nservicebus”.&#160; The thing is, they are hardly comparable.</p>
<p>Agatha is a Request/Response Service Layer framework.&#160; It basically supports synchronous and asynchronous Request/Response style communication and tries to make it as easy as possible to write a service layer for that type of communication.&#160; Apart from being easy to use, it also encourages a clean implementation of your service layer and a way to minimize the repetitiveness of cross-cutting concerns.&#160; It also enables you to get better performance than with typical Remote Procedure Call or Remote Method Invocation style service layers because it will try to minimize roundtrips by batching requests and responses together.&#160; In the next release, it will also offer a caching layer so certain requests (depending on how you set it up) don’t need to be processed and cached responses can simply be returned.&#160; There’s also support for one-way requests (or fire-and-forget requests) but it has the same downsides as one-way requests with typical WCF services have. That’s pretty much all it does.&#160; That’s probably all it’ll ever do.&#160; In short, it’s just an upgrade over your typical WCF services.</p>
<p>NServiceBus on the other hand also does Request/Response, but that’s just one of the things it can do.&#160; Again, Agatha is essentially an RPC or RMI framework whereas NServiceBus is built on top of one-way messaging technology.&#160; This allows for much more possibilities when it comes to communicating between different applications or different parts or processes within the same application boundary.&#160; A great overview of those possibilities can be found <a href="http://nservicebus.com/ArchitecturalPrinciples.aspx" target="_blank">here</a>.&#160; Because it is based on messaging, there are a lot of benefits that you can get from NServiceBus that you’ll probably never get from Agatha.&#160; For one, the ‘Store &amp; Forward’ messaging model from NServiceBus might seem similar to Agatha’s one-way requests on first sight, but there are some very important differences.&#160; If you send a fire-and-forget request with Agatha, and the service is currently down, then that request is essentially lost.&#160; With NServiceBus, the message is stored in a message queue and it will be processed when the target of the fire-and-forget message comes up again.&#160; From a reliability point of view, that’s obviously a tremendous improvement over what Agatha can offer you.&#160; Another area where NServiceBus truly shines (IMO) is in its <a href="http://en.wikipedia.org/wiki/Publish_subscribe" target="_blank">Publish/Subscribe</a> implementation.&#160; Some people have asked me if i’ll ever provide something like that in Agatha and the answer has always been ‘no’.&#160;&#160; For one, it doesn’t fit into what Agatha tries to do and i don’t see the point in implementing it if a better implementation is available already in another project.&#160;&#160; There’s plenty more interesting things in NServiceBus to deal with more advanced scenarios, which you’ll have to find out about on your own <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So which one is more suitable for you or your applications? As with every technology choice, it depends.&#160; Agatha is great for most typical business applications.&#160; If you need to communicate between one or more different clients (with different i don’t mean multiple instances but different types of clients like a web app, a silverlight client and/or a WPF client) and<em> one </em>service (you can obviously use it with more than one service as well if you want to) on an application server which encapsulates your business layer then it is a very attractive solution, as long as you don’t need the superior reliability that NServiceBus can offer you.&#160; With superior reliability i particularly mean the ability to still process received messages once the service layer comes back up after having been unavailable.&#160; In my experience, most business applications don’t really need that, since most of those applications are entirely unusable if the service they depend on is down.&#160; In short, if all the possible downsides of using a WCF service layer are not an issue for your project, then Agatha will be a great fit.</p>
<p>If however, you need to maximize reliability, performance and general robustness of a critical enterprise application, then NServiceBus will definitely be a much better choice.&#160; If you’re dealing with many distributed parts, NServiceBus will also make things much easier for you than Agatha (or any other WCF service layer for that matter) will.&#160;&#160; And obviously, if you want to integrate multiple applications while reducing coupling between applications as much as possible, NServiceBus will also be a much better fit than Agatha.&#160; With NServiceBus, you’d only need to share an assembly containing the types of the messages.&#160; With Agatha, you either need to share an assembly with shared request/response types or use proxies for them <em>and</em> you would also have to <em>know</em> about the other applications since you’d need to access their services directly.&#160; This can get quite ugly pretty fast.</p>
<p>And in some cases, you can just use both of them at the same time.&#160; At work we have two projects that use Agatha for all of their internal communication within their own application boundary, yet they use NServiceBus to notify each other of certain events.&#160; Neither of the applications knows about the existence of the other… the only thing they share is one assembly with some shared message types.&#160; We’ve also started working on a new platform where each application in the platform will use Agatha for all of the communication within their own application boundary (since they’re all typical silverlight clients backed by a WCF service style applications) but they will use NServiceBus for every kind of communication that goes outside of the application boundary.</p>
<p>As with many things, it’s just a matter of choosing the right tool for the right job.&#160; Hopefully, this post will help some of you make that decision should you need to make it in the future <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2010/01/agatha-vs-nservicebus/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
