blob: 67c2f24e23ffbdda3c33c211316aa0225393000a [file] [log] [blame]
<div class="wiki-content maincontent"><h2 id="EnterpriseIntegrationPatterns-EnterpriseIntegrationPatterns">Enterprise Integration Patterns</h2>
<p>Version 5.0 onwards of Apache ActiveMQ comes complete with full support for the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/toc.html" rel="nofollow">Enterprise Integration Patterns</a> (from the excellent book by <a shape="rect" class="external-link" href="http://www.amazon.com/exec/obidos/search-handle-url/105-9796798-8100401?%5Fencoding=UTF8&amp;search-type=ss&amp;index=books&amp;field-author=Gregor%20Hohpe" rel="nofollow">Gregor Hohpe</a> and <a shape="rect" class="external-link" href="http://www.amazon.com/exec/obidos/search-handle-url/105-9796798-8100401?%5Fencoding=UTF8&amp;search-type=ss&amp;index=books&amp;field-author=Bobby%20Woolf" rel="nofollow">Bobby Woolf</a>) via the <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/">Apache Camel library</a>. </p>
<p>You can easily add any of the supported <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/enterprise-integration-patterns.html">Enterprise Integration Patterns</a> into ActiveMQ (either on the JMS client or in the broker process) to support smart routing, transformation and a whole host of other powerful patterns. You can of course just embed <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/">Camel library</a> directly into your application, such as via <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/spring.html">Spring</a> as well..</p>
<p>This also means you can cleanly integrate all of the <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/components.html">Camel Components</a> into ActiveMQ so you can easily integrate with <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/cxf.html">CXF</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/file.html">Files</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/jbi.html">JBI</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/jpa.html">JPA</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/mail.html">Mail</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/mina.html">MINA</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/quartz.html">Quartz</a>, <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/xmpp.html">XMPP</a> and <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/components.html">many other protocols and transports!</a></p>
<h3 id="EnterpriseIntegrationPatterns-UsingEIPintheActiveMQBroker">Using EIP in the ActiveMQ Broker</h3>
<p>The broker's <strong>activemq.xml</strong> file comes already configured to support Camel; you just need to customize the routing rules.</p>
<h4 id="EnterpriseIntegrationPatterns-WritingEIPrulesusingJavacode">Writing EIP rules using Java code</h4>
<p>To use <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/dsl.html">Java code to write EIP routing rules</a>, just put your classes on the classpath (such as in activemq/lib/myroutes/foo.jar). Then to get Camel to find your routes you need to edit the activemq.xml so that the <strong>packages</strong> attribute points to the package name (or a parent package name) to look for.</p>
<p>For example if all your routes are in the package org.acme.cheese; such as org.acme.cheese.whatnot.MyRouter then you could edit the XML to be...</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
&lt;camelContext xmlns=&quot;http://activemq.apache.org/camel/schema/spring&quot;&gt;
&lt;package&gt;org.acme.cheese&lt;/package&gt;
&lt;/camelContext&gt;
]]></script>
</div></div>
<h4 id="EnterpriseIntegrationPatterns-WritingEIPrulesusingXML">Writing EIP rules using XML</h4>
<p>To use XML its even easier, as you can just embed whatever routing rules inside the &lt;camelContext&gt; element using Camel's <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/xml-configuration.html">Spring XML format</a>. Note that the XML is way more verbose than the <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/dsl.html">Java DSL</a> but it is a bit simpler to deploy. e.g. for a trivial route...</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
&lt;camelContext xmlns=&quot;http://activemq.apache.org/camel/schema/spring&quot;&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:com.acme.MyQueue&quot;/&gt;
&lt;to uri=&quot;activemq:com.acme.SomeOtherQueue&quot;/&gt;
&lt;/route&gt;
&lt;/camelContext&gt;
]]></script>
</div></div>
<h3 id="EnterpriseIntegrationPatterns-UsingEIPintheJMSclient">Using EIP in the JMS client</h3>
<p>You can use <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/">Camel</a> <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/endpoint.html">Endpoints</a> directly from your JMS client one of the following JMS destinations, depending on what JMS API you want it to use</p>
<ul><li><a shape="rect" class="external-link" href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/camel/CamelDestination.html">CamelDestination</a></li><li><a shape="rect" class="external-link" href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/camel/CamelQueue.html">CamelQueue</a></li><li><a shape="rect" class="external-link" href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/camel/CamelTopic.html">CamelTopic</a></li></ul>
<p>You can then use this destination like any other JMS destination when sending or receiving messages! This means you can use any of the <a shape="rect" class="external-link" href="http://activemq.apache.org/camel/components.html">large number of Camel components</a> from your JMS code, by just changing the Destination object!</p>
<h3 id="EnterpriseIntegrationPatterns-SeeAlso">See Also</h3>
<ul><li><a shape="rect" class="external-link" href="http://activemq.apache.org/camel/enterprise-integration-patterns.html">Enterprise Integration Patterns</a></li><li><a shape="rect" class="external-link" href="http://activemq.apache.org/camel/components.html">Camel Components</a></li><li><a shape="rect" class="external-link" href="http://activemq.apache.org/camel/xml-reference.html">Camel XML Reference</a></li></ul></div>