| <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&modificationDate=1117021488000&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&modificationDate=1117021488000&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;"> |
| <message-driven> |
| ... |
| <ejb-name>TopicDurableMDB</ejb-name> |
| <ejb-class>com.panacya.platform.service.bus.mdb.SimpleMessageReceiverBean</ejb-class> |
| <messaging-type>javax.jms.MessageListener</messaging-type> |
| ... |
| <activation-config> |
| <activation-config-property> |
| <activation-config-property-name>Destination</activation-config-property-name> |
| <activation-config-property-value>topic.testTopic</activation-config-property-value> |
| </activation-config-property> |
| <activation-config-property> |
| <activation-config-property-name>DestinationType</activation-config-property-name> |
| <activation-config-property-value>javax.jms.Topic</activation-config-property-value> |
| </activation-config-property> |
| ... |
| </activation-config> |
| ... |
| </message-driven> |
| </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;"> |
| <inbound-resourceadapter> |
| ... |
| <activationspec> |
| <activationspec-class>org.activemq.ra.ActiveMQActivationSpec</activationspec-class> |
| <required-config-property> |
| <config-property-name>Destination</config-property-name> |
| </required-config-property> |
| <required-config-property> |
| <config-property-name>DestinationType</config-property-name> |
| </required-config-property> |
| </activationspec> |
| ... |
| </inbound-resourceadapter> |
| </pre> |
| </div></div> |
| <p>In the <a shape="rect" href="inbound-communication.data/ejb-jar.xml?version=3&modificationDate=1117021488000&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&modificationDate=1117021488000&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&modificationDate=1117021488000&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 – invoker-proxy-binding</b></div><div class="codeContent panelContent pdl"> |
| <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> |
| <invoker-proxy-binding> |
| <name>activemq-message-driven-bean</name> |
| <invoker-mbean>default</invoker-mbean> |
| <proxy-factory>org.jboss.ejb.plugins.inflow.JBossMessageEndpointFactory</proxy-factory> |
| ... |
| </invoker-proxy-binding> |
| </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 – container-configuration</b></div><div class="codeContent panelContent pdl"> |
| <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> |
| <container-configuration> |
| <container-name>ActiveMQ Message Driven Bean</container-name> |
| <call-logging>false</call-logging> |
| <invoker-proxy-binding-name>activemq-message-driven-bean</invoker-proxy-binding-name> |
| ... |
| </container-configuration> |
| </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 – TopicDurableMDB</b></div><div class="codeContent panelContent pdl"> |
| <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> |
| <message-driven> |
| <ejb-name>TopicDurableMDB</ejb-name> |
| <resource-adapter-name>activemq-ra-1.2-SNAPSHOT.rar</resource-adapter-name> |
| <configuration-name>ActiveMQ Message Driven Bean</configuration-name> |
| </message-driven> |
| </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&modificationDate=1117021355000&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> |
| |