This section describes how to use TIBCO Enterprise Message Service to drive a Message Driven Bean (MDB) within WebLogic Server. It assumes you have already set up your environment as described in the previous section.
This example assumes that the application directory for the MDB is C:\Tibco\EMS\samples\client\bea\MDB
. You can change the configuration appropriately for a different directory.
ejb-jar.xml
file in the application directory as follows:<!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>MDB</ejb-name> <ejb-class>MDB</ejb-class> <transaction-type>Container</transaction-type> <message-driven-destination> <destination-type>javax.jms.Queue </destination-type> </message-driven-destination> <security-identity> <run-as> <role-name>everyone</role-name> </run-as> </security-identity> </message-driven> </enterprise-beans> <assembly-descriptor> <security-role> <role-name>everyone</role-name> </security-role> </assembly-descriptor> </ejb-jar>This file defines the EJB with a class name of "MDB" (file name
MDB.class
). The EJB container can manage transactions, and it specifies that the MDB reads from a Queue. Security for the EJB and MDB is set so that everyone can run it.Elements in this file are defined in the EJB 2.0 specification (see the EJB documentation at http://java.sun.com for more details).
weblogic-ejb-jar.xml
file in the same directory as follows:<?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>MDB</ejb-name> <message-driven-descriptor> <pool> <max-beans-in-free-pool>200 </max-beans-in-free-pool> <initial-beans-in-free-pool>20 </initial-beans-in-free-pool> </pool> <destination-jndi-name>myQueue</destination-jndi-name> <initial-context-factory> com.tibco.tibjms.naming.TibjmsInitialContextFactory </initial-context-factory> <provider-url>tibjmsnaming://localhost:7222 </provider-url> <connection-factory-jndi-name>QueueConnectionFactory </connection-factory-jndi-name> </message-driven-descriptor> <jndi-name>MDB</jndi-name> </weblogic-enterprise-bean> <security-role-assignment> <role-name>everyone</role-name> <principal-name>system</principal-name> </security-role-assignment> </weblogic-ejb-jar>This file further defines the EJB named MDB to indicate how to get to the connection factory and the queue by specifying the JNDI names for the factory and the destination and also the URL for the provider. This example points to the same JNDI provider that was set up in the prior section, that is the TIBCO Enterprise Message Service server, and it identifies
myQueue
as the JNDI destination name for the MDB. This configuration also indicates that initially 20 beans will be deployed and up to 200 may be run if necessary to handle the message traffic.The elements in this file are WebLogic Server-specific extensions to the EJB 2.0 specification. This file is more completely described at http://edocs.bea.com/wls/docs60/ejb/reference.html#1071166.
MDB.java
to the MDB
directory.import javax.ejb.CreateException; import javax.ejb.MessageDrivenBean; import javax.ejb.MessageDrivenContext; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; public class MDB implements MessageDrivenBean, MessageListener { private MessageDrivenContext context; // Required - public constructor with no argument public MDB () {} // Required - ejbActivate public void ejbActivate() {} // Required - ejbRemove public void ejbRemove() { context = null; } // Required - ejbPassivate public void ejbPassivate() {} public void setMessageDrivenContext( MessageDrivenContext mycontext) { context = mycontext; } // Required - ejbCreate() with no arguments public void ejbCreate () throws CreateException {} // Implementation of MessageListener - throws no exceptions public void onMessage(Message msg) { try { System.out.println("MDB: " + ((TextMessage)msg).getText() + " Thread: " + Thread.currentThread().getName()); Thread.sleep(2000, 0); } catch(Exception e) { // Catch any exception e.printStackTrace(); } } }
C:\bea\wlserver6.1\config\mydomain\setEnv.cmd
in the last section.mkdir build build\META-INF copy ejb-jar.xml build\META-INF copy weblogic-ejb-jar.xml build\META-INF javac -d build MDB.java cd build jar cvf myejb.jar META-INF MDB.class cd .. java weblogic.ejbc -compiler javac build\myejb.jar MDB.jar
MDB.jar
to the CLASSPATH
in startWebLogic.cmd
.../config/mydomain/config.xm
l, must be updated to deploy the EJB by adding the following lines before the final </domain>
line:<Application Name="MDB" Path="C:\TIBCO\EMS\samples\client\bea\MDB"> <EJBComponent Name="MDB" URI="MDB.jar" Targets="myserver"/> </Application>
t.java
, must be modified so that it only creates a foreign JMS provider message and sends it (take out the lines after TIBCOobject.JMSSend(msg);
so you do not receive it that is what the MDB is for). javac t.java
.QueueConnectionFactory
and myQueue
have already been created. In this example, the WebLogic Server, rather than the test program, reads from that queue.
TIBCO Enterprise Message Service™ Application Integration Guide Software Release 4.3, February 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |