Chapter 23
910
Running the Message-Driven Bean Example
Compile MyMessageBean.java. If you are using Weblogic server (as we will be for this example) you
should also create weblogic-ejb-jar.xml to set up the EJB as a subscriber on MyJMSTopic:
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0
EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>myMessageBean</ejb-name>
<message-driven-descriptor>
<destination-jndi-name>MyJMSTopic</destination-jndi-name>
</message-driven-descriptor>
<jndi-name>myMessageBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
Set up your JMS Server, as specified in the server documentation and configure MyJMSTopic. (You
already did this if you ran the Pub/Sub examples.)
Before you deploy the EJB you must make sure your container is EJB 2.0-compliant.
For Weblogic this can be achieved by downloading the EJB 2.0 upgrade from
http://commerce.bea.com/downloads/weblogic_server.jsp. Place the
ejb20.jar in the \lib directory inside the server directory.
Now create a JAR file called myMessageBean.jar with the following structure:
mailbean\
MyMessageBean.class
META-INF\
ejb-jar.xml
weblogic-ejb-jar.xml
Switch back to the Weblogic administration console and select Deployments | EJB. Click on Install a
new EJB... and then browse to the JAR file created above. Finally, click on Upload to deploy the EJB.
No explicit call to the EJB is needed as it is already listening on the topic specified in its deployment
descriptor. All that is required to complete this example is to run the Publisher from the first example.
MyMessageBean will print any messages that the Publisher sends:
You can also try modifying the deployment descriptor so that MyMessageBean listens on MyJMSQueue.
Then, it will work with the Sender from the PTP example.