Chapter 3 Integrating With JBoss 4.0.2 : Get the Example MDB Working Using JBossMQ

Get the Example MDB Working Using JBossMQ
1.
   %JBOSS_CLIENT%\jboss-j2ee.jar
2.
Compile the example MDB, TextMDB.java. The source code for this example is located in JBoss Administration and Development, Chapter 4, Example 2.
3.
Create a directory named META-INF in the output directory that now contains the org.jboss.chap4.ex2.TextMDB.class.
4.
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.
5.
   jar cvf myejb.jar META-INF org\jboss\chap4\ex2\TextMDB.class
6.
In JBoss 4.0.2, 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>
7.
Start the JBoss server by changing to the %JBOSS_HOME%\bin directory and issuing the following command:
   run
8.
Copy myejb.jar to %JBOSS_DEPLOY%.
9.
19:35:33,343 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/C:/jboss-4.0.2/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,service=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-4.0.2/server/default/deploy/myejb.jar
19:35:34,968 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/jboss-4.0.2/server/default/deploy/myejb.jar
10.
   %JBOSS_CLIENT%\jboss-j2ee.jar
   %JBOSS_CLIENT%\concurrent.jar
11.
Compile the client program, org.jboss.chap4.ex2.SendRecvClient.java. The source to this program is listed in the book JBoss Administration and Development.
12.
   %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).
13.
In JBoss 4.0.2, 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:
   java.naming.provider.url=localhost
14.
   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