<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Jakub Korab</title>
	
	<link>http://www.jakubkorab.net</link>
	<description>Adventures in technology consulting</description>
	<lastBuildDate>Fri, 16 Mar 2012 16:41:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JakubKorab" /><feedburner:info uri="jakubkorab" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Machiavelli (on software?)</title>
		<link>http://www.jakubkorab.net/2012/03/machiavelli-on-software.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=machiavelli-on-software</link>
		<comments>http://www.jakubkorab.net/2012/03/machiavelli-on-software.html#comments</comments>
		<pubDate>Fri, 16 Mar 2012 16:40:26 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=7038</guid>
		<description><![CDATA[<p>It must be remembered that there is nothing more difficult to plan, more doubtful of success, nor more dangerous to manage than the creation of a new system. For the initiator has the enmity of all who would profit by the preservation of the old institutions and merely lukewarm defenders in those who would gain by the new ones.</p>
<p>&#8211; Machiavelli &#8220;The Prince&#8221;</p>
]]></description>
			<content:encoded><![CDATA[<blockquote><p>It must be remembered that there is nothing more difficult to plan, more doubtful of success, nor more dangerous to manage than the creation of a new system. For the initiator has the enmity of all who would profit by the preservation of the old institutions and merely lukewarm defenders in those who would gain by the new ones.</p></blockquote>
<p>&#8211; Machiavelli &#8220;The Prince&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/03/machiavelli-on-software.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT side-effects at the NHS</title>
		<link>http://www.jakubkorab.net/2012/03/it-side-effects-at-the-nhs.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=it-side-effects-at-the-nhs</link>
		<comments>http://www.jakubkorab.net/2012/03/it-side-effects-at-the-nhs.html#comments</comments>
		<pubDate>Wed, 14 Mar 2012 16:25:32 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=7031</guid>
		<description><![CDATA[<p>My mother has a a phrase &#8211; professional illness. It&#8217;s the moment that she (an environmental engineer) walks into a random building and promptly looks at the air ducts. I suffer from the same thing &#8211; only around tech. Before and after the birth of my daughter, I have had more chances than ever to deal with the NHS. In that time, I witnessed a couple of events that made me step back and think about the way that IT ...read more]]></description>
			<content:encoded><![CDATA[<p>My mother has a a phrase &#8211; professional illness. It&#8217;s the moment that she (an environmental engineer) walks into a random building and promptly looks at the air ducts. I suffer from the same thing &#8211; only around tech. Before and after the birth of my daughter, I have had more chances than ever to deal with the NHS. In that time, I witnessed a couple of events that made me step back and think about the way that IT in general conducts itself. </p>
<p>I don&#8217;t work with end-user business apps these days, but having spent years doing just that, still feel the pain of those that do. While agility and user input are all the rage, the reality is that we as developers are often so disconnected from end users that we just don&#8217;t feel that pain, and some things don&#8217;t fit in neatly into bug reports. Add to the normal IT project multiple layers of go-betweens, project managers, business analysts, ivory tower architects, and things of concern fall through the cracks.</p>
<p>At a late stage appointment with a midwife, we had the pleasure of arriving on the day of the rollout of a new patient record system. We have all heard about these things, mostly because they&#8217;re delivered way over time and budget. It was interesting to see it from an end user perspective. Having spent an hour or so doing what midwives do, we sat down while for the first time a mid-50&#8242;s lady set down in front of a system she&#8217;d only ever presumably seen in an &#8220;induction&#8221;. Like code handovers, these involve a dreary talk to a group of people with some vague handwaving, all moving too fast for anyone to get a sense of what&#8217;s really going on. Then a pat on the back and &#8220;off you go&#8221;.</p>
<p>It all seemed so straightforward, a menu on the top all looking very Office 2010, a list of appointments in a side pane and forms to fill out. Everything looking uniform, and as a result fairly difficult to navigate without reading it all out. To the developers it must have all seemed so obvious, it&#8217;s just a forms application, and of course Checkup B follows Investigation A. It&#8217;s easy to think this way when you have been looking non-stop at the same app for weeks/months. A quick usability test with a fresh pair of eyes would have made life so much easier for a new user.</p>
<p>Coming in towards the end of the pregnancy we arrived, as you do, with a folder of paperwork from previous scans and checkups. Presumably this was exactly what this record system was to replace. You carry these collections of paper around the whole time, just in case something happens, so that the relevant health professionals can at a glance get your background details. It seems there was a bit of a hitch. In order to record details of a final scan, you <em>obviously</em> need the details of all the previous appointments. The system wouldn&#8217;t let you submit just that form. Cue 45 minutes of a midwife copying paperwork into the system, all while our eyes glazed over and other patients were filled up the waiting room. Major own goal, and yet so simple to deal with. Presumably since getting the data imported from paper would be impractical (mums aren&#8217;t going to hand over their potentially needed baby notes to get sent to an offshore data entry shop), either use the system for new pregnancies only, or loosen the constraints such that the workflow can be entered into in the middle.</p>
<p>Our next IT speedbump got me thinking about open standards/data, when a pediatric doctor checked Alex before discharge. The doctor had come from another hospital, and had no idea how to use the software at the one we were in. Presumably, both systems had access to the same data, though managed it differently. Open standards are often touted as a &#8220;Good Thing&#8221;, providers can develop systems that operate against those standards and consumers (hospitals, GP surgeries and the like) buy the &#8220;best&#8221; solutions (from an indistinguishable selection). On the face of it, the idea is actually quite good &#8211; increased competition yields better prices, and innovation (though I&#8217;m skeptical as to how much of that you can have filling in forms). I get the impression that side-effects such as the one of staff moving around having difficulties are the tip of the iceberg. Centralised procurement often yields sub-optimal results, and massive cost overruns from kitchen sink requirements. Building 95% similar systems over and over seems like it has its own problems. I don&#8217;t know what the answer to that one is, or whether one in fact exists, but I have no doubt it&#8217;s worth thinking about. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/03/it-side-effects-at-the-nhs.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alexandra</title>
		<link>http://www.jakubkorab.net/2012/03/alexandra.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=alexandra</link>
		<comments>http://www.jakubkorab.net/2012/03/alexandra.html#comments</comments>
		<pubDate>Sat, 10 Mar 2012 16:51:18 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[announcements]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=7023</guid>
		<description><![CDATA[<p>Born Wednesday the 8th of March. Mum and baby are back home and doing well.</p>
<p></p>
]]></description>
			<content:encoded><![CDATA[<p>Born Wednesday the 8th of March. Mum and baby are back home and doing well.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2012/03/image29.jpg"><img src="http://www.jakubkorab.net/wp-content/uploads/2012/03/image29.jpg" alt="" title="Alexandra" width="512" height="342" class="aligncenter size-medium wp-image-7024" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/03/alexandra.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Developing web services in ServiceMix</title>
		<link>http://www.jakubkorab.net/2012/02/developing-web-services-in-servicemix.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=developing-web-services-in-servicemix</link>
		<comments>http://www.jakubkorab.net/2012/02/developing-web-services-in-servicemix.html#comments</comments>
		<pubDate>Thu, 16 Feb 2012 10:17:52 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[cxf]]></category>
		<category><![CDATA[fusebyexample]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[servicemix]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=7005</guid>
		<description><![CDATA[<p>I have added a number of projects to FuseByExample/smx-ws-examples on GitHub that demonstrate how to go about developing a number of common web service use cases. The samples are designed to get you up and running quickly with SOAP based web services in an OSGi world.</p>
<p>The examples include:</p>

a Maven project that generates all relevant Java code from a WSDL using the cxf-codegen-plugin, and wraps it in an OSGi bundle
a plain Java web service implementation of a web service using CXF
an ...read more]]></description>
			<content:encoded><![CDATA[<p>I have added a number of projects to <a href="https://github.com/FuseByExample/smx-ws-examples" title="ServiceMix Web Service Examples">FuseByExample/smx-ws-examples</a> on GitHub that demonstrate how to go about developing a number of common web service use cases. The samples are designed to get you up and running quickly with SOAP based web services in an OSGi world.</p>
<p>The examples include:</p>
<ul>
<li>a Maven project that generates all relevant Java code from a WSDL using the <a href="http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html" title="cxf-codegen-plugin">cxf-codegen-plugin</a>, and wraps it in an OSGi bundle</li>
<li>a plain Java web service implementation of a web service using CXF</li>
<li>an implementation of the web service using a <a href="http://camel.apache.org/cxf.html" title="Camel CXF component">Camel CXF</a> route</li>
<li>a web service proxy using a Camel route</li>
<li>a client based on a Camel route that uses the CXF component to invoke those web services; no Java code required</li>
</ul>
<p>As usual, full documentation in the README. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/02/developing-web-services-in-servicemix.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Build-time integration testing OSGi bundles in ServiceMix</title>
		<link>http://www.jakubkorab.net/2012/02/build-time-integration-testing-osgi-bundles-in-servicemix.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=build-time-integration-testing-osgi-bundles-in-servicemix</link>
		<comments>http://www.jakubkorab.net/2012/02/build-time-integration-testing-osgi-bundles-in-servicemix.html#comments</comments>
		<pubDate>Fri, 10 Feb 2012 16:05:22 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[camel]]></category>
		<category><![CDATA[fusebyexample]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[servicemix]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6992</guid>
		<description><![CDATA[<p>I have just added a new project to GitHub under FuseByExample/smx-integration-testing that you can use to verify at build time that your bundles and features will deploy and run as expected in a specific version of ServiceMix. The intention is that you can use it to kick start testing in your own projects.</p>
<p>To do this I hooked up the process described by Ioannis Canellos in Advanced integration testing with Pax Exam Karaf to start up and deploy your project artifacts ...read more]]></description>
			<content:encoded><![CDATA[<p>I have just added a new project to GitHub under <a href="https://github.com/FuseByExample/smx-integration-testing" title="ServiceMix Integration Testing">FuseByExample/smx-integration-testing</a> that you can use to verify at build time that your bundles and features will deploy and run as expected in a specific version of ServiceMix. The intention is that you can use it to kick start testing in your own projects.</p>
<p>To do this I hooked up the process described by Ioannis Canellos in <a href="http://iocanel.blogspot.com/2012/01/advanced-integration-testing-with-pax.html">Advanced integration testing with Pax Exam Karaf</a> to start up and deploy your project artifacts into an embedded <a href="http://fusesource.com/products/enterprise-servicemix/" title="Enterprise ServiceMix">FuseSource distribution of ServiceMix</a> (4.4.1-fuse-01.13 at time of writing), using the <a href="http://maven.apache.org/plugins/maven-failsafe-plugin/" title="Maven Failsafe Plugin">maven-failsafe-plugin</a> for integration testing.</p>
<p>The result is a build that compiles and assembles your bundle or features project, unit tests it, packages it up for installation and then integration tests the binary using pax-exam-karaf and JUnit.</p>
<p>If your bundle fails either to install into the embedded ServiceMix container, or fails any of the criteria defined in your integration test, the build will fail and the build artifact won&#8217;t end up being installed to your Maven repo.</p>
<p>The sample demonstrates:</p>
<ul>
<li>the wiring required to assemble this approach in Maven</li>
<li>the separation of test artifacts for a SpringDM bundle into both unit and integration tests; abstracting out the OSGi bits for unit testing while ensuring <code>${}</code> placeholders work, and</li>
<li>shows a number of ways to exercise the code in your bundle via:</li>
<ul>
<li>straight Camel route testing</li>
<li>using the OSGi <code>BundleContext</code> to verify that a bundle is installed and active</li>
<li>checking that a SpringDM OSGi service is deployed via the <code>@Inject</code> mechanism</li>
</ul>
</ul>
<p>The documentation in the README file goes into full detail as to how this is achieved.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/02/build-time-integration-testing-osgi-bundles-in-servicemix.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bootstrap Projects for Getting Started with ServiceMix 4</title>
		<link>http://www.jakubkorab.net/2012/01/bootstrap-projects-for-getting-started-with-servicemix-4.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=bootstrap-projects-for-getting-started-with-servicemix-4</link>
		<comments>http://www.jakubkorab.net/2012/01/bootstrap-projects-for-getting-started-with-servicemix-4.html#comments</comments>
		<pubDate>Tue, 03 Jan 2012 11:51:09 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[activemq]]></category>
		<category><![CDATA[announcements]]></category>
		<category><![CDATA[camel]]></category>
		<category><![CDATA[fusebyexample]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[servicemix]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6981</guid>
		<description><![CDATA[<p>Over the Christmas break I cleaned up and published a set of Maven projects for getting started with ServiceMix 4.4.1+ into GitHub. I found myself reusing the same code for a number of activities, and figured it may be of broader use to others. You can find it under FuseByExample/smx-bootstraps.</p>
<p>smx-bootstraps contains within it a set of OSGI Blueprints (DI, based on the ideas behind Spring) bundles that exercise some of the core things that you will want to do with ...read more]]></description>
			<content:encoded><![CDATA[<p>Over the Christmas break I cleaned up and published a set of Maven projects for getting started with ServiceMix 4.4.1+ into GitHub. I found myself reusing the same code for a number of activities, and figured it may be of broader use to others. You can find it under <a href="https://github.com/FuseByExample/smx-bootstraps" title="ServiceMix Bootstraps">FuseByExample/smx-bootstraps</a>.</p>
<p><code>smx-bootstraps</code> contains within it a set of OSGI Blueprints (DI, based on the ideas behind Spring) bundles that exercise some of the core things that you will want to do with ServiceMix:</p>
<ul>
<li>    defining services in bundles that can be reused in other bundles</li>
<li>    use Camel for writing integration code</li>
<li>    use ActiveMQ for sending persistent messages between bundles, regardless of whether they are in the same container or in others</li>
<li>    request-response over messaging</li>
<li> <strong>Update 20/02/2012:</strong> RESTful web services!!! </li>
<li>    externalising your environment configuration</li>
<li>    group bundles into features</li>
</ul>
<p>The README document at the project root explains how to get started with ServiceMix, deploy bundles, change code and play with config.</p>
<p>Why would you want to use them?</p>
<p>ServiceMix went through a massive generational change between versions 3.X and 4.X, moving from JBI to an OSGi based model. While development work on it is proceeding at a huge rate, the documentation hasn&#8217;t kept up &#8211; although it is being brought up to date in the background. <code>smx-bootstraps</code> contains small artifacts that are hopefully easy to understand and play with, along with instructions on how to use them in the container.</p>
<p>The project may also be use of use as a starting starting point to further development. A fairly clean project layout exists that you can use as a reference point, which acts as a supplement to the Maven archetypes that are publicly available, such as:</p>
<ul>
<li>    <code>org.apache.camel.archetypes:camel-archetype-blueprint</code> for generating Blueprint bundles to run Camel routes; similar to <code>smx-pinger</code> and <code>smx-ponger</code> bundles in <code>smx-bootstraps</code></li>
<li>    <code>org.apache.karaf.archetypes:karaf-blueprint-archetype</code> for generating simple Blueprint bundles; such as the <code>smx-ponger-service</code> bundle</li>
</ul>
<p>I have found these bundles to be a really handy way of exercising ServiceMix features, and working with various configurations. Not having to code up something new each time is a huge time saver. Hopefully you should find this as well.</p>
<p>I expect to expand this little project as time goes on and I find myself recreating other use cases, such as exposing web services &#8211; next on my &#8220;todo list&#8221;. Please drop me a line at &#8220;jakub dot korab at gmail&#8221; if you find this useful or have any ideas that would fit in well. Of course being GitHub, feel free to fork it or contribute back changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2012/01/bootstrap-projects-for-getting-started-with-servicemix-4.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Understanding ActiveMQ Broker Networks</title>
		<link>http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=understanding-activemq-broker-networks</link>
		<comments>http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html#comments</comments>
		<pubDate>Tue, 29 Nov 2011 17:07:31 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[activemq]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6956</guid>
		<description><![CDATA[<p>Networks of message brokers in ActiveMQ work quite differently to more familiar models such as that of physical networks. They are not any harder to understand or reason about but we need to have an appreciation as to what exactly each of the pieces in the puzzle do by themselves in order to understand them in them large. I will try to explain each component piece progressively moving up in complexity from a single broker through to a full blown ...read more]]></description>
			<content:encoded><![CDATA[<p><a href="http://activemq.apache.org/networks-of-brokers.html" title="Networks of brokers - the official docs">Networks of message brokers in ActiveMQ</a> work quite differently to more familiar models such as that of physical networks. They are not any harder to understand or reason about but we need to have an appreciation as to what exactly each of the pieces in the puzzle do by themselves in order to understand them in them large. I will try to explain each component piece progressively moving up in complexity from a single broker through to a full blown network. At the end you should have a feel of how these networks behave and be able to reason about the interactions across different topologies.</p>
<p>One of the key things in understanding broker-based messaging is that the production, or sending of a message, is disconnected from the consumption of that message. The broker acts as an intermediary, serving to make the method by which a method is consumed as well as the route that the message has travelled orthogonal to its production. You shouldn&#8217;t need to understand the entire postal system to know that you post a letter in the big red box and eventually it will arrive in the little box at the front of the recipient&#8217;s house. Same idea applies here.</p>
<div id="attachment_6963" class="wp-caption aligncenter" style="width: 488px"><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/producerConsumer1.gif"><img class="size-full wp-image-6963" title="producerConsumer" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/producerConsumer1.gif" alt="" width="478" height="104" /></a><p class="wp-caption-text">Producer and consumer are unaware of each other; only the broker they are connected to</p></div>
<p>Connections are shown in the direction of where they were established from (i.e. Consumer connects to Broker).</p>
<p>Out of the box when a standard message is sent to a queue from a producer, it is sent to the broker, which persists it in its message store. By default this is in KahaDB, but it can configured to be stored in memory, which buys performance at the cost of reliability. Once the broker has confirmation that the message has been persisted in the journal (the terms journal and message store are often used interchangeably), it responds with an acknowledgement back to the producer. The thread sending the message from the producer is blocked at this time.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/producer.gif"><img class="aligncenter size-full wp-image-6964" title="producer" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/producer.gif" alt="" width="345" height="276" /></a></p>
<p>On the consumption side, when a message listener is registered or a call to receive() is made, the broker creates a subscription to that queue. Messages are fetched from the message store and passed to the consumer; it&#8217;s usually done in batches, and the fetching is a lot more complex than simply read from disk, but that&#8217;s the general idea. With the default behaviour, assuming the <code>Session.AUTO_ACKNOWLEDGE</code> is being used, the consumer will acknowledge that the message has been received <em>before processing it</em>. On receiving the acknowledgement, the broker updates the message store marking that message as consumed, or just deletes it (this depends on the persistence mechanism).</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/consumer1.gif"><img class="aligncenter size-full wp-image-6965" title="consumer" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/consumer1.gif" alt="Consuming messages" width="358" height="278" /></a></p>
<p>If you want the consumer to acknowledge the message <em>after</em> it has been sucessfully consumed, you need to <a href="http://www.jakubkorab.net/2011/08/configuring-activemq-transactions-in-spring.html" title="Configuring ActiveMQ transactions in Spring">set up transaction management</a>, or handle it manually using <code>Session.CLIENT_ACKNOWLEDGE</code>.</p>
<p>So what happens when there are more than one consumer on a queue? All things being equal, and ignoring consumer priorities, the broker will in this case hand out incoming messages in a round-robin manner to each subscriber.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoConsumersOneBroker.gif"><img class="aligncenter size-full wp-image-6966" title="twoConsumersOneBroker" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoConsumersOneBroker.gif" alt="" width="447" height="295" /></a></p>
<p><strong>Store-and-forward</strong></p>
<p>Now to scale this up to two brokers, Broker1 and Broker2. In ActiveMQ a network of brokers is set up by connecting a <code>networkConnector</code> to a <code>transportConnector</code> (think of it as a socket listening on a port). A <code>networkConnector</code> is an outbound connection from one broker to another.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoBrokers.gif"><img class="aligncenter size-full wp-image-6967" title="twoBrokers" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoBrokers.gif" alt="" width="482" height="356" /></a></p>
<p>When a subscription is made to a queue on Broker2, that broker tells the other brokers that it knows about (in our case, just Broker1) that it is interested in that queue; another subscription is now made on Broker1 with Broker2 as the consumer. As far as an ActiveMQ broker is concerned there is no difference between a standard client consuming messages, or another broker acting on behalf of a client. <strong>They are treated in the exact same manner.</strong></p>
<p>So now that Broker1 sees a subscription from Broker2, what happens? The result is a hybrid of the two producer and consumer behaviours. Broker1 is the producer, and Broker2 the consumer. Messages are fetched from Broker1&#8242;s message store, passed to Broker2. Broker2 processes the message by <code>store</code>-ing it in its journal, and acknowledges consumption of that message. Broker1 then marks the message as consumed.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardTwoBrokers.gif"><img class="aligncenter size-full wp-image-6968" title="storeAndForwardTwoBrokers" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardTwoBrokers.gif" alt="" width="358" height="278" /></a></p>
<p>The simple consume case then applies as Broker2 <code>forward</code>s the message to its consumers, as tough the message was produced directly into it. Neither the producer nor consumer are aware that any network of brokers exists, it is orthogonal to their functionality &#8211; a key driver of this style of messaging.</p>
<p><strong>Local and remote consumers</strong></p>
<p>It has already been noted that as far as a broker is concerned, all subscriptions are equal. To it there is no difference between a local &#8220;real&#8221; consumer, and another broker that is going to forward those messages on. Hence incoming messages will be handed out round-robin as usual. If we have 2 consumers &#8211; Consumer1 on Broker1, and Consumer2 on Broker2 &#8211; if messages are produced to Broker1, both consumers will each receive the same number of messages.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoConsumersTwoBrokers.gif"><img class="aligncenter size-full wp-image-6969" title="twoConsumersTwoBrokers" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/twoConsumersTwoBrokers.gif" alt="" width="551" height="277" /></a></p>
<p>A <code>networkConnector</code> is unidirectional by default, which means that the broker initiating the connector acts as a client, forwarding its subscriptions. Broker2 in this case subscribes on behalf of its consumers to Broker1. Broker2 however will not be made aware of subscriptions on Broker1. <code>networkConnector</code>s can however be made duplex, such that subscriptions are passed in both directions.</p>
<p>So let&#8217;s take it one step further with a network that demonstrates why it is a bad idea to connect brokers to each other in an ad-hoc manner. Let&#8217;s add Broker3 into the mix such that it connects into Broker1, and Broker2 sets up a second networkConnector into Broker3. All </code>networkConnector</code>s are set up as <em>duplex</em>.</p>
<p><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardThreeBrokers.gif"><img class="aligncenter size-full wp-image-6970" title="storeAndForwardThreeBrokers" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardThreeBrokers.gif" alt="" width="473" height="263" /></a></p>
<p>This is a common approach people take when they first encounter broker networks and want to connect a number of brokers to each other, as they are naturally used to the internet model of network behaviour where traffic is routed down the shortest path. If we think about it from first principles, it quickly becomes apparent that is not the best approach. Let's examine what happens when a consumer connects to Broker2.</p>
<ol>
<li>Broker2 echoes the subscription to the brokers it knows about - Broker1 and Broker3.</li>
<li>Broker3 echoes the subscription down all <code>networkConnector</code>s other than the one from which the request came; it subscribes to Broker1.</li>
<li>A producer sends messages into Broker1.</li>
<li>Broker1 stores and forwards messages to the active subscriptions on it's <code>transportConnector</code>; half to Broker2, and half to Broker3.</li>
<li>Broker2 stores and forwards to it's consumer.</li>
<li>Broker3 stores and forwards to Broker2.</li>
</ol>
<p>Eventually everything ends up at the consumer, but some messages ended up needlessly travelling <code>Broker1-&gt;Broker3-&gt;Broker2</code>, while the others went by the more direct route <code>Broker1-&gt;Broker2</code>. Add more brokers into the mix, and the store-and-forward traffic increases exponentially as messages flow through any number of weird and wonderful routes.</p>
<div id="attachment_6971" class="wp-caption aligncenter" style="width: 486px"><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardFourBrokers.gif"><img class="size-full wp-image-6971" title="storeAndForwardFourBrokers" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/storeAndForwardFourBrokers.gif" alt="" width="476" height="243" /></a><p class="wp-caption-text">Very bad! Lots of unnecessary store-and-forward.</p></div>
<p>Fortunately, it is possible to avoid this by employing other topologies, such as hub and spoke.</p>
<div id="attachment_6972" class="wp-caption aligncenter" style="width: 495px"><a href="http://www.jakubkorab.net/wp-content/uploads/2011/11/hubAndSpoke.gif"><img class="size-full wp-image-6972" title="hubAndSpoke" src="http://www.jakubkorab.net/wp-content/uploads/2011/11/hubAndSpoke.gif" alt="" width="485" height="387" /></a><p class="wp-caption-text">Better. A message can flow between any of the numbered brokers via the hub and a maximum of 3 hops (though it puts a lot of load onto the hub broker).</p></div>
<p>You can also use a more nuanced approach that includes considerations such as unidirectional <code>networkConnector</code>s that pass only a certain subscriptions, or reducing consumer priority such that further consumers have a lower priority than closer ones.</p>
<p>Each network design needs to be considered separately and trades off considerations such message load, amount of hardware at your disposal, latency (number of hops) and reliability. When you understand how all the parts fit and think about the overall topology from first principles, it's much easier to work through.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Batching JMS messages for performance; not so fast</title>
		<link>http://www.jakubkorab.net/2011/09/batching-jms-messages-for-performance-not-so-fast.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=batching-jms-messages-for-performance-not-so-fast</link>
		<comments>http://www.jakubkorab.net/2011/09/batching-jms-messages-for-performance-not-so-fast.html#comments</comments>
		<pubDate>Mon, 12 Sep 2011 16:21:42 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[activemq]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6921</guid>
		<description><![CDATA[<p>Recently an idea had crossed my radar around speeding up performance of messaging producers; batching messages into a single transaction. The idea being that there is overhead in the standard behaviour of a message bus that can be optimised out if you group messages into a single transaction.</p>
<p>My initial thoughts about this were that it was unlikely; at best the performance would be the same as an untransacted client. The comments were framed in conversations of Spring&#8217;s JMSTemplate, which continually ...read more]]></description>
			<content:encoded><![CDATA[<p>Recently an idea had crossed my radar around speeding up performance of messaging producers; batching messages into a single transaction. The idea being that there is overhead in the standard behaviour of a message bus that can be optimised out if you group messages into a single transaction.</p>
<p>My initial thoughts about this were that it was unlikely; at best the performance would be the same as an untransacted client. The comments were framed in conversations of Spring&#8217;s <code>JMSTemplate</code>, which continually walks the object tree <code>ConnectionFactory</code> -&gt; <code>Connection</code> -&gt; <code>Session</code> -&gt; <code>MessageProducer</code>, and back closing them off. Each close causes some network traffic between the library and the bus. My thoughts were that perhaps the discussion hadn&#8217;t accounted for caching these objects via a <code>CachingConnectionFactory</code>. I resolved to find out.</p>
<p>My other concern was that while it could be done in the general case, it didn&#8217;t make a lot of sense.</p>
<p>Generally speaking there are two categories of messages that will concern an application developer. Sending throwaway messages that aren&#8217;t critical is one thing &#8211; you can not persist them on the broker side and save 90% of the overhead. You can also do asynchronous sends, which won&#8217;t persist the messages and save further time by not giving your app confirmation that the broker received them. If you lose them, it won&#8217;t be a big deal.</p>
<p>The other type are the ones that you really care about. Things that reflect or affect a change in the real world &#8211; orders, instructions, etc. The value of a broker in this case comes from knowing that once it has the message, it will be dealt with. </p>
<p>In ActiveMQ, this guarantee comes via the message store. When you send a message the broker will not acknowledge receipt until the message has been persisted. If the broker goes down, it can be restarted, and any persisted messages may be consumed as though nothing happened, or another broker takes over transparently using the same message store (HA). As you can imagine, there is natural overhead. Two network traversals, and some I/O to disk. Keep this in mind.</p>
<p>I tested a couple of different scenarios.</p>
<ul>
<li><code>JMSTemplate</code> with a <code>CachingConnectionFactory</code>. This is the baseline.</li>
<li>An untransacted, persistent session. Each message gets sent off to the broker as they come in. The broker places the message in a persistent store. This is like the logic of the JMSTemplate, but where you control the lifecycles of JMS objects.</li>
<li>An untransacted, unpersisted session. Each message gets sent off to the broker as they come in. The broker stores the message in memory only for delivery.</li>
<li>Transacted sessions. Messages get bundled together into a transaction and committed.</li>
</ul>
<p>Messages were posted to a queue with no consumers on a single broker with default setttings.</p>
<p>The results surprised me.</p>
<p><div id="attachment_6934" class="wp-caption aligncenter" style="width: 593px"><a href="http://www.jakubkorab.net/wp-content/uploads/2011/09/log_send_time.jpg"><img src="http://www.jakubkorab.net/wp-content/uploads/2011/09/log_send_time.jpg" alt="" title="Average message send time" width="583" height="339" class="size-full wp-image-6934" /></a><p class="wp-caption-text">Average message send time</p></div><br />
<div id="attachment_6936" class="wp-caption aligncenter" style="width: 594px"><a href="http://www.jakubkorab.net/wp-content/uploads/2011/09/log_messages_per_second.jpg"><img src="http://www.jakubkorab.net/wp-content/uploads/2011/09/log_messages_per_second.jpg" alt="" title="Average message throughput" width="584" height="340" class="size-full wp-image-6936" /></a><p class="wp-caption-text">Average message throughput</p></div></p>
<p>Timings should be considered indicative only, and are only there for a relative comparison. Initial spikes should be considered part of a warm-up, and ignored.</p>
<p>Firstly, getting down to the JMS API was consistently faster than with <code>JMSTemplate</code> (not surprising in hindsight given its object walk). There was also indeed an upshot in performance from batching messages together for delivery in a transaction. The more messages there were in a batch, the better the performance (I repeated this with 10, 100 and 1000 messages per transaction). The results approached those of the non-persistent delivery mode, but never quite reached it. What accounts for this?</p>
<p>I did some digging, and came up with <a title="How do transactions work?" href="http://activemq.apache.org/how-do-transactions-work.html">this description of transactions in ActiveMQ</a>. It appears that there is a separate store in memory for uncommitted transactions. While a transaction is open messages are placed here, and are then copied over to the main store on commit.</p>
<p>So what to make of this? Should you forgo <code>JMSTemplate</code> and batch everything? Well, as with pretty much anything, it depends.</p>
<p><code>JMSTemplate</code> is simple to configure and use &#8211; it also ties in nicely to the various Spring abstractions (<code>TransactionManager</code>s come to mind). There are certainly some upsides to getting down to the JMS API, however they come at a cost of time coding and losing those hooks; which you might regret later.</p>
<p>Batching itself is a funny one, in that it&#8217;s one of those things that could be easily misused. <em>Transactions are not there for improving performance</em>. They exist as a logical construct for making atomic changes. If you batch up messages in memory to send to the broker for a performance upshot that are unrelated; and your container goes down before you&#8217;ve had a chance to commit; you have violated the contract of &#8220;this business action has been completed&#8221;, and you lost your messages. Not something you want for important, change-the-world messages.</p>
<p>If you have messages that are relatively unimportant that won&#8217;t affect the correct operation of your system, there are better options available to you for improving performance such as dropping persistence.</p>
<p>If, however, you have related messages tied to a single operation, then perhaps getting down to the JMS API and batching these together under a single transaction is something you might want to consider. The key here is ensuring that you don&#8217;t lose the real meaning of transaction.</p>
<hr/>
<strong>Update 1 (13/11):</strong> Replaced graphs with log scale to make the series clearer.</p>
<p><strong>Update 2 (13/11):</strong>Thanks to James Strachan for an extended explanation:</p>
<p>The reason transactions are so much faster on the client site can be explained comparing it to the normal case, where the client blocks until the message has definitely gone to disk on the broker.</p>
<p>In a transaction the JMS client doesn&#8217;t need to wait until the broker confirms the message because it&#8217;s going straight into the transactional store (memory). Because the broker will complain on a commit if something has gone awry, the client can afford to not block at all doing a send or acknowledge (not even blocking for it to be sent over the socket), so it behaves like a true async operation. This means it&#8217;s very fast. </p>
<p>This explains why transactional performance approaches that of asych operations with the size of the batch &#8211; because for all intents and purposes it is nearly asynchronous. The only cost is that of the synchronous <code>commit()</code>, which is a flush from the transactional store to the journal.</p>
<p>You could argue that this doesn&#8217;t really affect the actual throughput &#8211; as the difference between batching &#038; no transactions is just the client sitting around blocking. The benefit of the transactions is that it&#8217;s making each client much more effective. I.e. to get equivalent throughput you would need more clients running concurrently. In the case of the Camel, this could be achieved by configuring in a larger thread pool.</p>
<p><a href="http://activemq.apache.org/should-i-use-transactions.html" title="Should I use transactions?">A brief outline of when to use transactions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2011/09/batching-jms-messages-for-performance-not-so-fast.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring ActiveMQ transactions in Spring</title>
		<link>http://www.jakubkorab.net/2011/08/configuring-activemq-transactions-in-spring.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=configuring-activemq-transactions-in-spring</link>
		<comments>http://www.jakubkorab.net/2011/08/configuring-activemq-transactions-in-spring.html#comments</comments>
		<pubDate>Tue, 16 Aug 2011 11:41:35 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[activemq]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6902</guid>
		<description><![CDATA[<p>It&#8217;s easy to configure Message Driven POJOs over ActiveMQ with Spring, but slightly more involved once you want to get transactions working correctly; here&#8217;s how to do it.</p>
<p>Start with a basic DefaultMessageListenerContainer config.</p>

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34;
    xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
    xmlns:amq=&#34;http://activemq.apache.org/schema/core&#34;
    xmlns:context=&#34;http://www.springframework.org/schema/context&#34;
    xsi:schemaLocation=&#34;http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://activemq.apache.org/schema/core

http://activemq.apache.org/schema/core/activemq-core.xsd&#34;&#62;

    &#60;!-- setup an embedded JMS Broker for testing purposes --&#62;
    &#60;amq:broker id=&#34;my-broker&#34; useJmx=&#34;false&#34; persistent=&#34;false&#34; brokerName=&#34;localhost&#34;&#62;
       ...read more]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to configure Message Driven POJOs over ActiveMQ with Spring, but slightly more involved once you want to get transactions working correctly; here&#8217;s how to do it.</p>
<p>Start with a basic <code>DefaultMessageListenerContainer</code> config.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xmlns:amq=&quot;http://activemq.apache.org/schema/core&quot;
    xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
    xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://activemq.apache.org/schema/core

http://activemq.apache.org/schema/core/activemq-core.xsd&quot;&gt;

    &lt;!-- setup an embedded JMS Broker for testing purposes --&gt;
    &lt;amq:broker id=&quot;my-broker&quot; useJmx=&quot;false&quot; persistent=&quot;false&quot; brokerName=&quot;localhost&quot;&gt;
        &lt;amq:transportConnectors&gt;
            &lt;amq:transportConnector uri=&quot;tcp://localhost:61616&quot; /&gt;
        &lt;/amq:transportConnectors&gt;
    &lt;/amq:broker&gt;

    &lt;bean id=&quot;amq.connectionFactory&quot;
            class=&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;&gt;
        &lt;property name=&quot;brokerURL&quot;
                value=&quot;tcp://localhost:61616?jms.redeliveryPolicy.maximumRedeliveries=1&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;consumer.connectionFactory&quot;
            class=&quot;org.springframework.jms.connection.CachingConnectionFactory&quot;&gt;
        &lt;constructor-arg ref=&quot;amq.connectionFactory&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;consumer.messageListener&quot;
            class=&quot;net.jakubkorab.amq.CountingMessageListener&quot; /&gt;

    &lt;bean id=&quot;consumer.jmsContainer&quot;
            class=&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;consumer.connectionFactory&quot; /&gt;
        &lt;property name=&quot;destinationName&quot; value=&quot;sample.messages&quot; /&gt;
        &lt;property name=&quot;messageListener&quot; ref=&quot;consumer.messageListener&quot; /&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>An embedded broker is started, and a <code>MessageListener</code> (<code>CountingMessageListener</code>) is set up to pick up messages from a queue (<code>sample.messages</code>). <code>MessageListenerContainer</code>s should always sit over a <code>CachingConnectionFactory</code> (see the Spring docs for <a href="http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/jms.html">details</a>). So what happens if the listener throws an exception?</p>
<p>According to the intent of the URI configration on the connection factory, we&#8217;d like to see the broker attempt to redeliver the message again, and if that fails the message should end up in a dead letter queue (<code>ActiveMQ.DLQ</code>). However, if you test it, that&#8217;s not what happens at all. </p>
<p>You will not see any further redelivery attempts and there&#8217;s nothing in the dead letter queue. Why? Because you haven&#8217;t configured up a <code>TransactionManager</code>, Spring&#8217;s <code>DefaultMessageListenerContainer</code> picks up the message and immediately acknowledges it. As far as the broker is concerned, it&#8217;s job is done.</p>
<p>So let&#8217;s remedy this by adding one.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;bean id=&quot;local.transactionManager&quot;
            class=&quot;org.springframework.jms.connection.JmsTransactionManager&quot;&gt;
        &lt;!-- can also refer to amq.connectionFactory --&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;consumer.connectionFactory&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;consumer.jmsContainer&quot;
            class=&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;consumer.connectionFactory&quot; /&gt;
        &lt;property name=&quot;destinationName&quot; value=&quot;topic:sample.messages&quot; /&gt;
        &lt;property name=&quot;messageListener&quot; ref=&quot;consumer.messageListener&quot; /&gt;
        &lt;!-- add a reference to the transaction manager --&gt;
        &lt;property name=&quot;transactionManager&quot; ref=&quot;local.transactionManager&quot; /&gt;
    &lt;/bean&gt;
</pre>
<p>This uses Spring&#8217;s own <code>TransactionManager</code> instance to now make sure that the message is consumed with no issues. Any exceptions thrown will now cause the broker to redeliver the message according to the redelivery policy specified in the connection URI, and once that is exceeded to send the offending message to the dead letter queue.</p>
<hr />
<strong>Update 13/09:</strong> Thanks to Sue Macey for pointing out this fragment from the Spring docs:</p>
<blockquote><p>
Local resource transactions can simply be activated through the <code>sessionTransacted</code> flag on the listener container definition. Each message listener invocation will then operate within an active JMS transaction, with message reception rolled back in case of listener execution failure. Sending a response message (via <code>SessionAwareMessageListener</code>) will be part of the same local transaction, but any other resource operations (such as database access) will operate independently. This usually requires duplicate message detection in the listener implementation, covering the case where database processing has committed but message processing failed to commit.</p></blockquote>
<hr />
<p>This is sufficient for most cases. However let&#8217;s say you want to update a database via your listener. Transactions ought to be atomic, and the <code>JmsTransactionManager</code> won&#8217;t do the job for you here &#8211; you need to bring out the big guns. </p>
<p>Once you start managing more than one resource (broker, database etc) in a transaction, you bring in a sizeable overhead. <a href="http://en.wikipedia.org/wiki/Distributed_transactions">Distributed transactions</a> will involve some sort of two-phase commit protocol, and the chatter adds processing time to each operation. Should you decide that it&#8217;s definitely something you want to do, JTA is the tool for the job.</p>
<p>If you&#8217;re running in a full JEE container and using a <code>DataSource</code> that supports XA transactions (some do, some don&#8217;t), you&#8217;re in luck:</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;bean id=&quot;consumer.messagerListener&quot;
            class=&quot;net.jakubkorab.amq.DBAwareMessageListener&quot; &gt;
        &lt;!-- listener uses a JdbcTemplate with a DataSource defined elsewhere --&gt;
        &lt;property name=&quot;dataSource&quot; ref=&quot;xa.dataSource&quot; /&gt;
    &lt;/bean&gt;

    &lt;!-- use the XA-specific version of the connection factory --&gt;
    &lt;bean id=&quot;amq.connectionFactory&quot;
            class=&quot;org.apache.activemq.ActiveMQXAConnectionFactory&quot;
            depends-on=&quot;my-broker&quot;&gt;
        &lt;property name=&quot;brokerURL&quot;
                value=&quot;tcp://localhost:61616?jms.redeliveryPolicy.maximumRedeliveries=1&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;jta.transactionManager&quot;
            class=&quot;org.springframework.transaction.jta.JtaTransactionManager&quot;
            depends-on=&quot;my-broker&quot;/&gt;

    &lt;bean id=&quot;consumer.jmsContainer&quot;
            class=&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;consumer.connectionFactory&quot; /&gt;
        &lt;property name=&quot;destinationName&quot; value=&quot;sample.messages&quot; /&gt;
        &lt;property name=&quot;messageListener&quot; ref=&quot;consumer.messagerListener&quot; /&gt;
        &lt;!-- change the transaction manager reference --&gt;
        &lt;property name=&quot;transactionManager&quot; ref=&quot;jta.transactionManager&quot; /&gt;
        &lt;!--
            now tell the broker that it's involved in a transaction; this has the same effect
            as creating a transacted session using the JMS API
        --&gt;
        &lt;property name=&quot;sessionTransacted&quot; value=&quot;true&quot; /&gt;
    &lt;/bean&gt;
</pre>
<p>The <code>JtaTransactionManager</code> will pick up and manage transactional resources using the JTA implementation from the server. However, you need a full JEE server for this. Tomcat for example, does not come with JTA. Neither for that matter will JUnit, which makes testing your transaction config problematic. In these cases, you need to make use of an external JTA implementation, such as Atomikos or JTOM.</p>
<p>Atomikos&#8217; approach to transaction management outside of the server is to place their own wrappers around your resource definitions. Their transaction manager will then scan the Spring <code>ApplicationContext</code> to find these. To set it up takes a final step:</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;!-- implementation-specific wrapper used by the transaction manager --&gt;
    &lt;bean id=&quot;xa.connectionFactory&quot; class=&quot;com.atomikos.jms.AtomikosConnectionFactoryBean&quot;&gt;
        &lt;property name=&quot;uniqueResourceName&quot; value=&quot;amq1&quot; /&gt;
        &lt;property name=&quot;xaConnectionFactory&quot; ref=&quot;amq.connectionFactory&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;jta.transactionManager&quot;
            class=&quot;org.springframework.transaction.jta.JtaTransactionManager&quot;&gt;
        &lt;property name=&quot;transactionManager&quot;&gt;
            &lt;bean class=&quot;com.atomikos.icatch.jta.UserTransactionManager&quot;
                    init-method=&quot;init&quot;
                    destroy-method=&quot;close&quot;&gt;
                &lt;property name=&quot;forceShutdown&quot; value=&quot;false&quot; /&gt;
            &lt;/bean&gt;
        &lt;/property&gt;
        &lt;property name=&quot;userTransaction&quot;&gt;
            &lt;bean class=&quot;com.atomikos.icatch.jta.UserTransactionImp&quot;&gt;
                &lt;property name=&quot;transactionTimeout&quot; value=&quot;300&quot; /&gt;
            &lt;/bean&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</pre>
<p>The <code>JtaTransactionManager</code> is configured to use an external underlying <code>TransactionManager</code> implementation, and wrappers are provided around the resources.</p>
<p>Assuming interaction with an HSQLDB instance, which doesn&#8217;t support XA transactions, you would add a further:</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;!-- HSQLDB is not XA compatible so we wrap that using a special Atomikos NonXA to XA DataSource --&gt;
    &lt;bean id=&quot;xa.dataSource&quot; class=&quot;com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean&quot;&gt;
        &lt;property name=&quot;uniqueResourceName&quot; value=&quot;hsqldb&quot; /&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;org.hsqldb.jdbcDriver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:hsqldb:mem:myTestDb&quot; /&gt;
        &lt;property name=&quot;user&quot; value=&quot;sa&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
        &lt;property name=&quot;poolSize&quot; value=&quot;3&quot; /&gt;
    &lt;/bean&gt;
</pre>
<p>When using a database that supports XA, you would use a <code>com.atomikos.jdbc.AtomikosDataSourceBean</code> instead.</p>
<p>The above should get you going, but remember that it&#8217;s important with any kind of transactional config to test that it actually works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2011/08/configuring-activemq-transactions-in-spring.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Give your DB the love it deserves</title>
		<link>http://www.jakubkorab.net/2011/04/give-your-db-the-love-it-deserves.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=give-your-db-the-love-it-deserves</link>
		<comments>http://www.jakubkorab.net/2011/04/give-your-db-the-love-it-deserves.html#comments</comments>
		<pubDate>Wed, 20 Apr 2011 17:50:43 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.jakubkorab.net/?p=6890</guid>
		<description><![CDATA[<p>Pity the poor database. As critical to most apps as a foundation to a building. And as interesting as an accounting seminar at a nudist colony. </p>
<p>Not sexy enough for the attentions of the senior dev, or considered to be &#8220;well understood&#8221;, DB work frequently end up getting handed off to the junior guys on the team. Who promptly make all the mistakes the senior guys have learned not to make. Mistakes which end up with massive hunks of sub-optimal ...read more]]></description>
			<content:encoded><![CDATA[<p>Pity the poor database. As critical to most apps as a foundation to a building. And as interesting as an accounting seminar at a nudist colony. </p>
<p>Not sexy enough for the attentions of the senior dev, or considered to be &#8220;well understood&#8221;, DB work frequently end up getting handed off to the junior guys on the team. Who promptly make all the mistakes the senior guys have learned not to make. Mistakes which end up with massive hunks of sub-optimal compensating code in layers above them. Then they write some code off the back of them. Viola! Instant technical debt.</p>
<p>Queue self-perpetuating &#8220;<a href="http://www.mongodb-is-web-scale.com/">relational databases aren&#8217;t web scale</a>&#8220;, &#8220;normalised schemas aren&#8217;t performant&#8221;, &#8220;You don&#8217;t have these problems with NoSQL&#8221;.</p>
<p>Senior guys often don&#8217;t have the time to deal with it. DBAs aren&#8217;t seen as being responsive enough for JFDI/iterative development. Peer review at the end is too late.</p>
<p>So what&#8217;s the fix? Just enough design. Back of napkin. Whack together a schema, and talk through with someone (else) who knows what they&#8217;re doing. Then code. It&#8217;s not rocket science.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakubkorab.net/2011/04/give-your-db-the-love-it-deserves.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

