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. Copy the files ejb-jar.xml and jboss.xml from the source directory associated with Example 2 of Chapter 4 of JBoss Administration and Development, to the META-INF directory.
  6. Create the EJB jar file by changing directories to the output directory and issuing the following command:
  7.    jar cvf myejb.jar META-INF org\jboss\chap4\ex2\TextMDB.class 
    
  8. Map Connection Factory Names
  9. In JBoss 3.2.3, 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%\jms\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>  
    
  10. Start the JBoss server by changing to the %JBOSS_HOME%\bin directory and issuing the following command:
  11.    run  
    
  12. Copy myejb.jar to %JBOSS_DEPLOY%.
  13. In the JBoss window, you should see output similar to the following:
  14. 19:35:33,343 INFO  [org.jboss.deployment.MainDeployer] Starting deployment of 
    package: file:/C:/jboss-3.2.3/server/default/deploy/myejb.jar 
    19:35:34,296 INFO  [org.jboss.ejb.EjbModule] Deploying TextMDB 
    19:35:34,875 INFO  [org.jboss.ejb.plugins.jms.DLQHandler] Started null 
    19:35:34,875 INFO  [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Started 
    jboss.j2ee:binding=message-driven-bean,jndiName=local/TextMDB,plugin=invoker,serv
    ice=EJB 
    19:35:34,875 INFO  [org.jboss.ejb.plugins.MessageDrivenInstancePool] Started 
    jboss.j2ee:jndiName=local/TextMDB,plugin=pool,service=EJB 
    19:35:34,875 INFO  [org.jboss.ejb.MessageDrivenContainer] Started 
    jboss.j2ee:jndiName=local/TextMDB,service=EJB 
    19:35:34,875 INFO  [org.jboss.ejb.EjbModule] Started 
    jboss.j2ee:module=myejb.jar,service=EjbModule 
    19:35:34,875 INFO  [org.jboss.ejb.EJBDeployer] Deployed: 
    file:/C:/jboss-3.2.3/server/default/deploy/myejb.jar 
    19:35:34,968 INFO  [org.jboss.deployment.MainDeployer] Deployed package: 
    file:/C:/jboss-3.2.3/server/default/deploy/myejb.jar 
    
  15. To build the client program, make sure the following are in your CLASSPATH:
  16.    %JBOSS_CLIENT%\jboss-j2ee.jar  
       %JBOSS_CLIENT%\concurrent.jar  
    
  17. Compile the client program, org.jboss.chap4.ex2.SendRecvClient.java. The source to this program is listed in the book JBoss Administration and Development.
  18. To run the client program, add the following to your CLASSPATH:
  19.    %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_CLIENT%  
     

    The %JBOSS_CLIENT% directory is included so that the file jndi.properties in that directory can be found (see the next step).

  20. In JBoss 3.2.3, a jndi.properties file 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 add the following line in the copied file:
  21.    java.naming.provider.url=localhost 
    
  22. Run the client program:
  23.    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#8 sendRecvAsync, sent text=A text msg#9 End sendRecvAsync onMessage, recv text=A text msg#0processed by: 3824284 onMessage, recv text=A text msg#3processed by: 32953059  .... onMessage, recv text=A text msg#6processed by: 32420722 onMessage, recv text=A text msg#8processed by: 23916456

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

    20:03:25,046 INFO [STDOUT] TextMDB.ctor, this=3824284 20:03:25,078 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=3824284 20:03:25,078 INFO [STDOUT] TextMDB.ejbCreate, this=3824284 20:03:25,109 INFO [STDOUT] TextMDB.ctor, this=2003839 20:03:25,109 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=2003839 20:03:25,109 INFO [STDOUT] TextMDB.ejbCreate, this=2003839 20:03:25,109 INFO [STDOUT] TextMDB.ctor, this=30170403 20:03:25,125 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=30170403 20:03:25,125 INFO [STDOUT] TextMDB.ejbCreate, this=30170403 20:03:25,109 INFO [STDOUT] TextMDB.ctor, this=32953059 20:03:25,140 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=32953059 20:03:25,140 INFO [STDOUT] TextMDB.ejbCreate, this=32953059 20:03:25,125 INFO [STDOUT] TextMDB.ctor, this=31834937 20:03:25,156 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=31834937 20:03:25,156 INFO [STDOUT] TextMDB.ejbCreate, this=31834937 20:03:25,187 INFO [STDOUT] TextMDB.onMessage, this=3824284 20:03:25,187 INFO [STDOUT] TextMDB.sendReply, this=3824284, dest=QUEUE.A 20:03:25,125 INFO [STDOUT] TextMDB.ctor, this=13863286 20:03:25,203 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=13863286 20:03:25,203 INFO [STDOUT] TextMDB.ejbCreate, this=13863286 20:03:25,203 INFO [STDOUT] TextMDB.onMessage, this=32953059 20:03:25,218 INFO [STDOUT] TextMDB.sendReply, this=32953059, dest=QUEUE.A 20:03:25,234 INFO [STDOUT] TextMDB.onMessage, this=3824284 20:03:25,234 INFO [STDOUT] TextMDB.sendReply, this=3824284, dest=QUEUE.A 20:03:25,218 INFO [STDOUT] TextMDB.ctor, this=32420722 20:03:25,250 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=32420722 20:03:25,250 INFO [STDOUT] TextMDB.ejbCreate, this=32420722 20:03:25,296 INFO [STDOUT] TextMDB.ctor, this=23916456 20:03:25,296 INFO [STDOUT] TextMDB.setMessageDrivenContext, this=23916456 20:03:25,296 INFO [STDOUT] TextMDB.ejbCreate, this=23916456 20:03:25,312 INFO [STDOUT] TextMDB.onMessage, this=31834937 20:03:25,312 INFO [STDOUT] TextMDB.sendReply, this=31834937, dest=QUEUE.A 20:03:25,328 INFO [STDOUT] TextMDB.onMessage, this=2003839 20:03:25,328 INFO [STDOUT] TextMDB.sendReply, this=2003839, dest=QUEUE.A 20:03:25,296 INFO [STDOUT] TextMDB.onMessage, this=32953059 20:03:25,343 INFO [STDOUT] TextMDB.sendReply, this=32953059, dest=QUEUE.A 20:03:25,343 INFO [STDOUT] TextMDB.onMessage, this=13863286 20:03:25,343 INFO [STDOUT] TextMDB.sendReply, this=13863286, dest=QUEUE.A 20:03:25,328 INFO [STDOUT] TextMDB.onMessage, this=30170403 20:03:25,343 INFO [STDOUT] TextMDB.sendReply, this=30170403, dest=QUEUE.A 20:03:25,375 INFO [STDOUT] TextMDB.onMessage, this=32420722 20:03:25,375 INFO [STDOUT] TextMDB.sendReply, this=32420722, dest=QUEUE.A 20:03:25,421 INFO [STDOUT] TextMDB.onMessage, this=23916456 20:03:25,421 INFO [STDOUT] TextMDB.sendReply, this=23916456, 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