Get the Example MDB Working Using JBossMQ


  1. To build the example MDB, add the following to your CLASSPATH:
  2.    %JBOSS_CLIENT%\jboss-j2ee.jar   
    
  3. Compile the example MDB, TextMDB.java. The source code for this example is located in JBoss Administration and Development, Chapter 4, Example 2.
  4. Create a directory named META-INF in the output directory that now contains the org.jboss.chap4.ex2.TextMDB.class.
  5. Create the ejb-jar.xml and jboss.xml files in the META-INF directory. The code for these files is listed in Jboss Administration and Development, but the code below has slight modifications.
ejb-jar.xml
<?xml version="1.0"?>  
<!-- The ejb-jar.xml descriptor -->  
<!DOCTYPE ejb-jar   
  PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise   
   JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd" >  
  
<ejb-jar>   
  <enterprise-beans>   
    <message-driven>   
      <ejb-name>TextMDB</ejb-name>   
        <ejb-class>org.jboss.chap4.ex2.TextMDB</ejb-class>  
        <transaction-type>Container</transaction-type>   
        <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>   
        <message-driven-destination>   
          <destination-type>javax.jms.Queue</destination-type>   
        </message-driven-destination>   
        <resource-ref>   
          <res-ref-name>jms/QCF</res-ref-name>   
          <res-type>javax.jms.QueueConnectionFactory</res-type>   
          <res-auth>Container</res-auth>   
        </resource-ref>   
    </message-driven>   
  </enterprise-beans>   
</ejb-jar>   
jboss.xml
<?xml version="1.0"?>  
<!-- The jboss.xml descriptor -->   
<jboss>   
  <enterprise-beans>   
    <message-driven>   
      <ejb-name>TextMDB</ejb-name>   
      <destination-jndi-name>queue/B</destination-jndi-name>   
      <resource-ref>   
        <res-ref-name>jms/QCF</res-ref-name>   
        <jndi-name>QueueConnectionFactory</jndi-name>   
      </resource-ref>   
    </message-driven>   
  </enterprise-beans>   
</jboss>  
  1. Create the EJB jar file by changing directories to the output directory and issuing the following command:
  2.    jar cvf myejb.jar META-INF org\jboss\chap4\ex2\TextMDB.class 
    
  3. Map Connection Factory Names
  4. In JBoss 3.0.4, the JNDI names QueueConnectionFactory and TopicConnectionFactory do not come pre-mapped to the internal JBoss connection factory called ConnectionFactory. Therefore you must add this mapping in order to use the example MDB without modification. The mapping must be configured by adding the following lines in the file %JBOSS_DEPLOY%\jbossmq-service.xml:

    <!--========================================================== -->  
    <!-- JBossMQ                                                   -->  
    <!--========================================================== -->  
      
    <mbean code="org.jboss.naming.NamingAlias"  
    name="DefaultDomain:service=NamingAlias,fromName=QueueConnectionFactory">  
       <attribute name="ToName">ConnectionFactory</attribute>  
       <attribute name="FromName">QueueConnectionFactory</attribute>  
    </mbean>  
    <mbean code="org.jboss.naming.NamingAlias"  
    name="DefaultDomain:service=NamingAlias,fromName=TopicConnectionFactory">  
       <attribute name="ToName">ConnectionFactory</attribute>  
       <attribute name="FromName">TopicConnectionFactory</attribute>  
    </mbean>  
    
  5. Start the JBoss server by changing to the %JBOSS_HOME%\bin directory and issuing the following command:
  6.    run  
    
  7. Copy myejb.jar to %JBOSS_DEPLOY%.
  8. In the JBoss window, you should see output similar to the following:
  9.    12:04:09,172 INFO  [EjbModule] Creating  
       12:04:09,192 INFO  [EjbModule] Deploying TextMDB  
       12:04:10,214 WARN  [SecurityManager] No SecurityMetadadata was  
       available for B adding default security conf  
       12:04:10,284 INFO  [EjbModule] Created  
       12:04:10,294 INFO  [EjbModule] Starting  
       12:04:10,304 INFO  [EjbModule] Started  
       12:04:10,304 INFO  [MainDeployer] 
       deployment of package:  
       file:/C:/jboss-3.0.0/server/default/deploy/myejb.jar  
    
  10. To build the client program, make sure the following are in your CLASSPATH:
  11.    %JBOSS_CLIENT%\jboss-j2ee.jar  
       %JBOSS_CLIENT%\concurrent.jar  
    
  12. Compile the client program, org.jboss.chap4.ex2.SendRecvClient.java. The source to this program is listed in Jboss Administration and Development.
  13. To run the client program, add the following to your CLASSPATH:
  14.    %JBOSS_CLIENT%\jnp-client.jar  
       %JBOSS_CLIENT%\jbossmq-client.jar  
       %JBOSS_CLIENT%\jboss-common-client.jar 
       %JBOSS_CLIENT%\jnet.jar 
       %JBOSS_CLIENT%\log4j.jar  
       %JBOSS_HOME%\client  
     

    The %JBOSS_HOME%\client directory is included so that the file jndi.properties in that directory can be found.

    In JBoss 3.0.4, a jndi.properties does not come pre-configured for the client, therefore, you will have to create one. The easiest way is to first copy jndi.properties from %JBOSS_CONF% to %JBOSS_CLIENT%. Then, un-comment the following line in the copied file:

       java.naming.provider.url=localhost
  15. Run the client program:
  16.    java org.jboss.chap4.ex2.SendRecvClient  
     

    You should see output like the following in the client program window:

       Begin sendRecvAsync    sendRecvAsync, sent text=A text msg#0    sendRecvAsync, sent text=A text msg#1    sendRecvAsync, sent text=A text msg#2    sendRecvAsync, sent text=A text msg#3    ...    End sendRecvAsync    onMessage, recv text=A text msg#0processed by: 7438914    onMessage, recv text=A text msg#1processed by: 1639412    onMessage, recv text=A text msg#2processed by: 10668    onMessage, recv text=A text msg#3processed by: 1611150    ...

    You should also see output like the following in the JBoss server console:

       [INFO,Default] TextMDB.ctor, this=7438914    [INFO,Default] TextMDB.setMessageDrivenContext, this=7438914    [INFO,Default] TextMDB.ejbCreate, this=7438914    [INFO,Default] TextMDB.ctor, this=1639412    [INFO,Default] TextMDB.setMessageDrivenContext, this=1639412    [INFO,Default] TextMDB.ejbCreate, this=1639412    [INFO,Default] TextMDB.onMessage, this=7438914    [INFO,Default] TextMDB.sendReply, this=7438914, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=10668    [INFO,Default] TextMDB.setMessageDrivenContext, this=10668    [INFO,Default] TextMDB.ejbCreate, this=10668    [INFO,Default] TextMDB.onMessage, this=1639412    [INFO,Default] TextMDB.sendReply, this=1639412, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=1611150    [INFO,Default] TextMDB.setMessageDrivenContext, this=1611150    [INFO,Default] TextMDB.ejbCreate, this=1611150    [INFO,Default] TextMDB.onMessage, this=10668    [INFO,Default] TextMDB.sendReply, this=10668, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=6808485    [INFO,Default] TextMDB.setMessageDrivenContext, this=6808485    [INFO,Default] TextMDB.ejbCreate, this=6808485    [INFO,Default] TextMDB.onMessage, this=1611150    [INFO,Default] TextMDB.sendReply, this=1611150, dest=QUEUE.A    [INFO,Default] TextMDB.onMessage, this=6808485    [INFO,Default] TextMDB.sendReply, this=6808485, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=3277650    [INFO,Default] TextMDB.setMessageDrivenContext, this=3277650    [INFO,Default] TextMDB.ejbCreate, this=3277650    [INFO,Default] TextMDB.ctor, this=5224450    [INFO,Default] TextMDB.setMessageDrivenContext, this=5224450    [INFO,Default] TextMDB.ejbCreate, this=5224450    [INFO,Default] TextMDB.onMessage, this=3277650    [INFO,Default] TextMDB.sendReply, this=3277650, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=4280406    [INFO,Default] TextMDB.setMessageDrivenContext, this=4280406    [INFO,Default] TextMDB.ejbCreate, this=4280406    [INFO,Default] TextMDB.onMessage, this=5224450    [INFO,Default] TextMDB.sendReply, this=5224450, dest=QUEUE.A    [INFO,Default] TextMDB.ctor, this=4977982    [INFO,Default] TextMDB.onMessage, this=4280406    [INFO,Default] TextMDB.sendReply, this=4280406, dest=QUEUE.A    [INFO,Default] TextMDB.setMessageDrivenContext, this=4977982    [INFO,Default] TextMDB.ejbCreate, this=4977982    [INFO,Default] TextMDB.ctor, this=6805499    [INFO,Default] TextMDB.setMessageDrivenContext, this=6805499    [INFO,Default] TextMDB.ejbCreate, this=6805499    [INFO,Default] TextMDB.onMessage, this=4977982    [INFO,Default] TextMDB.sendReply, this=4977982, dest=QUEUE.A    [INFO,Default] TextMDB.onMessage, this=6805499    [INFO,Default] TextMDB.sendReply, this=6805499, dest=QUEUE.A

TIBCO Enterprise Message Service™ Application Integration Guide
Software Release 4.3, February 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com