Step Four: Write the deployment descriptors for the MDB
At deployment time, we tell the container the information about our
MDB. You use standard EJB deployment descriptors to setup
MDBs. Therefore, we need a
META-INF directory to house
our descriptor files.
ejb-jar file, we place the fully qualified
class name of the MDB, the destination type of the bean, and security
information etc. The file follows; notice the class name and the JMS
destination type. (The tag
changed by the specication authors from
<jms-destination-type>. You may need to use
<jms-destination-type> if you are using BEA
Where do we tell it the NAME of the queue? This goes in the vendor
specific file. For example, if you were deploying this on BEA WebLogic
6.0 you would have the
weblogic-ejb-jar.xml file that
<ejb-name> links you to the bean definition
ejb-jar.xml. Then we can setup pool information. In
this example, we are going to have 5 MDBs instantiated at deployment
with the ability to increase to 200. This will allow us to have 200
concurrent messages hitting the queue. The
<destination-jndi-name> is where we tell the
container to look at the EmailQueue. Since we do not have this in
code, if the JMS environment changed, we could just change this XML
file, and redeploy the bean.
Step Five: Package up the code
Now we have gotten the code, and the deployment descriptors, we need to package it to deploy on the EJB server. The directory structure should look like
util directories should be the compiled classes;
Now we archive the code and the deployment descriptors via:
../code% jar cvf emailmdb.jar com META-INF
Now we have the Email MDB in a jar file that we deploy to an EJB
server. To test, after deploying the bean, run the client, and you
should see the EJB server sending out an email. You may need to make
sure that the JavaMail API
mail.jar is at the beginning
CLASSPATH for your EJB server.
We have created a Message Driven Bean, showing how simple it is to tie into JMS as a consumer. Message Driven Beans are a nice addition to the EJB component architecture, offering a way for developers to create consumers that are pooled, transactional, and use the container's infrastructure.
Return to ONJava.com.