blob: 560d137ea90edde31a71b149d2649c5b79ab8fe1 [file] [log] [blame]
<div class="wiki-content maincontent">
<h2 id="InboundCommunication-INLINEConfiguringanMDBtoreceivemessagesfromActiveMQ">Configuring an MDB to receive messages from ActiveMQ</h2>
<p>There are three MDBs declared in the <a shape="rect" href="inbound-communication.data/ejb-jar.xml?version=3&amp;modificationDate=1117021488000&amp;api=v2" data-linked-resource-id="3249" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="ejb-jar.xml" data-nice-type="XML File" data-linked-resource-content-type="text/xml" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">ejb-jar.xml</a> deployment descriptor. For this example, I will be explaining how to configure the <code>TopicDurableMDB</code> to be invoked by JBoss when a message is received on an ActiveMQ Topic.</p>
<h3 id="InboundCommunication-TheBean">The Bean</h3>
<p>In the <a shape="rect" href="inbound-communication.data/ejb-jar.xml?version=3&amp;modificationDate=1117021488000&amp;api=v2" data-linked-resource-id="3249" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="ejb-jar.xml" data-nice-type="XML File" data-linked-resource-content-type="text/xml" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">ejb-jar.xml</a> deployment descriptor, the <code>TopicDurableMDB</code> is declared as follows:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>ejb-jar.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;message-driven&gt;
...
&lt;ejb-name&gt;TopicDurableMDB&lt;/ejb-name&gt;
&lt;ejb-class&gt;com.panacya.platform.service.bus.mdb.SimpleMessageReceiverBean&lt;/ejb-class&gt;
&lt;messaging-type&gt;javax.jms.MessageListener&lt;/messaging-type&gt;
...
&lt;activation-config&gt;
&lt;activation-config-property&gt;
&lt;activation-config-property-name&gt;Destination&lt;/activation-config-property-name&gt;
&lt;activation-config-property-value&gt;topic.testTopic&lt;/activation-config-property-value&gt;
&lt;/activation-config-property&gt;
&lt;activation-config-property&gt;
&lt;activation-config-property-name&gt;DestinationType&lt;/activation-config-property-name&gt;
&lt;activation-config-property-value&gt;javax.jms.Topic&lt;/activation-config-property-value&gt;
&lt;/activation-config-property&gt;
...
&lt;/activation-config&gt;
...
&lt;/message-driven&gt;
</pre>
</div></div>
<p>The <code>activation-config</code> element and it's child element, <code>activation-config-property</code>, are new elements for EJBs, so you might not be familiar with them. I won't go into to much detail about them, but it is important to understand that this is the first mechanism you use to link an MDB to a JCA. </p>
<h3 id="InboundCommunication-TheConnector">The Connector</h3>
<p>The two <code>activation-config-properties</code> shown above link to the following elements in the <a shape="rect" class="external-link" href="http://activemq.codehaus.org/checkout/activemq/modules/ra/src/rar/META-INF/ra.xml" rel="nofollow">ra.xml</a> file, which is contained within the <a shape="rect" href="jboss-integration.html">activemq-ra-1.2.rar</a> file:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>ra.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;inbound-resourceadapter&gt;
...
&lt;activationspec&gt;
&lt;activationspec-class&gt;org.activemq.ra.ActiveMQActivationSpec&lt;/activationspec-class&gt;
&lt;required-config-property&gt;
&lt;config-property-name&gt;Destination&lt;/config-property-name&gt;
&lt;/required-config-property&gt;
&lt;required-config-property&gt;
&lt;config-property-name&gt;DestinationType&lt;/config-property-name&gt;
&lt;/required-config-property&gt;
&lt;/activationspec&gt;
...
&lt;/inbound-resourceadapter&gt;
</pre>
</div></div>
<p>In the <a shape="rect" href="inbound-communication.data/ejb-jar.xml?version=3&amp;modificationDate=1117021488000&amp;api=v2" data-linked-resource-id="3249" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="ejb-jar.xml" data-nice-type="XML File" data-linked-resource-content-type="text/xml" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">ejb-jar.xml</a> file section shown above, the value of the <code>Destination</code> property is set to <code>topic.testTopic</code>. This value is the physical name of the ActiveMQ destination the <code>TopicDurableMDB</code> will be receiving messages from and not a JNDI name. In other words, the value of the <code>Destination</code> property has no meaning to JBoss. It is purely an ActiveMQ setting. </p>
<h3 id="InboundCommunication-TheGlue">The Glue</h3>
<p>In JBoss, the thing which connects an inbound JMS destination to an MDB is a JBoss container. To use ActiveMQ as the inbound message source for the <code>TopicDurableMDB</code> we must configure a new JBoss container. We do this in the <a shape="rect" href="inbound-communication.data/jboss.xml?version=3&amp;modificationDate=1117021488000&amp;api=v2" data-linked-resource-id="3251" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="jboss.xml" data-nice-type="XML File" data-linked-resource-content-type="text/xml" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">jboss.xml</a> file.</p>
<p>Three things are needed in the <a shape="rect" href="inbound-communication.data/jboss.xml?version=3&amp;modificationDate=1117021488000&amp;api=v2" data-linked-resource-id="3251" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="jboss.xml" data-nice-type="XML File" data-linked-resource-content-type="text/xml" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">jboss.xml</a> file in order to tie an MDB to a connector. They are:</p>
<ol><li>Configure a new <code>invoker-proxy-binding</code> that declares <code>JBossMessageEndpointFactory</code> as the <code>proxy-factory</code></li><li>Configure a new MDB container which uses the new <code>invoker-proxy-binding</code></li><li>Declare which MDBs should go into the new container</li></ol>
<p>This first snippet configures a new <code>invoker-proxy-binding</code>:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>jboss.xml &#8211; invoker-proxy-binding</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;invoker-proxy-binding&gt;
&lt;name&gt;activemq-message-driven-bean&lt;/name&gt;
&lt;invoker-mbean&gt;default&lt;/invoker-mbean&gt;
&lt;proxy-factory&gt;org.jboss.ejb.plugins.inflow.JBossMessageEndpointFactory&lt;/proxy-factory&gt;
...
&lt;/invoker-proxy-binding&gt;
</pre>
</div></div>
<p>This second snippet configures a new MDB container which uses the <code>invoker-proxy-binding</code> configured above:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>jboss.xml &#8211; container-configuration</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;container-configuration&gt;
&lt;container-name&gt;ActiveMQ Message Driven Bean&lt;/container-name&gt;
&lt;call-logging&gt;false&lt;/call-logging&gt;
&lt;invoker-proxy-binding-name&gt;activemq-message-driven-bean&lt;/invoker-proxy-binding-name&gt;
...
&lt;/container-configuration&gt;
</pre>
</div></div>
<p>This third snippet links the <code>TopicDurableMDB</code> to the <a shape="rect" href="jboss-integration.html">activemq-ra-1.2.rar</a> connector and tells JBoss to put instances of <code>TopicDurableMDB</code> into the new MDB container declared above:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>jboss.xml &#8211; TopicDurableMDB</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;message-driven&gt;
&lt;ejb-name&gt;TopicDurableMDB&lt;/ejb-name&gt;
&lt;resource-adapter-name&gt;activemq-ra-1.2-SNAPSHOT.rar&lt;/resource-adapter-name&gt;
&lt;configuration-name&gt;ActiveMQ Message Driven Bean&lt;/configuration-name&gt;
&lt;/message-driven&gt;
</pre>
</div></div>
<p>The above examples highlight the key configuration settings needed to enable MDBs deployed in JBoss to process messages from an ActiveMQ destination. </p>
<p>You can try the above example, plus a few more, by downloading the <a shape="rect" href="inbound-communication.data/activemq-jboss-test.zip?version=3&amp;modificationDate=1117021355000&amp;api=v2" data-linked-resource-id="3278" data-linked-resource-version="3" data-linked-resource-type="attachment" data-linked-resource-default-alias="activemq-jboss-test.zip" data-nice-type="Zip Archive" data-linked-resource-content-type="application/zip" data-linked-resource-container-id="35943" data-linked-resource-container-version="53">activemq-jboss-test.zip</a> file which contains the complete sample project.</p></div>