MDB With Non-Container-Specific-Annotations


Jay SenSharma

Jay SenSharma

Here in this post there are some standard MDB3.0 annotations are demonstrated which can be used to make our MDBs Code Container Independent. Now if we use the following Properties as part of @javax.ejb.ActivationConfigProperty then our MDB will become Vendor independent and then we can deploy the same MDB in most of the Popular containers like OC4J, WebLogic…etc.

Advantage of using @javax.ejb.ActivationConfigProperty annotation is …It eliminates the presence of “weblogic-ejb-jar.xml” (WebLogic Specific configuration file for EJBs).

NOTE: If we will provide @javax.ejb.ActivationConfigProperty and “weblogic-ejb-jar.xml” file configurations together then Always “weblogic-ejb-jar.xml” file configuration will take precedence over the Annotations.


activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") ,
@ActivationConfigProperty(propertyName="destinationJndiName", propertyValue="TestQ")

More Examples can be seen in the following Link:    mdb3-0-sample-for-weblogic-application-server/

For Informations And Meaning about the Tags of “weblogic-ejb-jar.xml” Please refer to:

Below are the Tags of “weblogic-ejb-jar.xml” and their Equivalent proeprties which can be used in the @ActivationConfigProperty

WebLogic 10.3.3 provides Support for many Properties Mentioned Below:

connection-factory-jndi-name (Equivalent Property: connectionFactoryJndiName)
destination-jndi-name (Equivalent Property: destinationJndiName)
distributed-destination-connection (Equivalent Property:distributedDestinationConnection)

connection-factory-resource-link (Equivalent Property: connectionFactoryResourceLink )
resource-adapter-jndi-name (Equivalent Property: resourceAdapterJndiName)
destination-resource-link (Equivalent Property: destinationResourceLink)

Jms-polling-interval-seconds(Equivalent Property: jmsPollingIntervalSeconds )
jms-client-id(Equivalent Property: jmsClientId)
durable-subscription-deletion (Equivalent Property: durableSubscriptionDeletion )
max-messages-in-transaction (Equivalent Property: maxMessagesInTransaction)
max-suspend-seconds (Equivalent Property: maxSuspendSeconds)
init-suspend-seconds (Equivalent Property: initSuspendSeconds)

use81-style-polling (Equivalent Property: use81StylePolling)
initial-context-factory (Equivalent Property: initialContextFactory)
provider-url (Equivalent Property: providerURL)

Jay SenSharma

MDB3.0 Sample for WebLogic Application Server

Hi All,

Jay SenSharma

Jay SenSharma

Here is a Example of MDB 3.0 which gets deployed on WebLogic Server 10 and above and starts consuming messages from javax.jms.Queue . This Example demonstrates us, How we can develop MDB3.0 for Oracle WebLogic Application Server.

For More details on MDB3.0 Standard Annotations which makes our MDB Application container specific API independent please refer to the following link:   MDB With Non-Container-Specific-Annotations

Step 1). first of all we need to develop  the MDB class like below

package ejb30;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ejb.ActivationConfigProperty;

activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") ,
@ActivationConfigProperty(propertyName="destinationJndiName", propertyValue="TestQ")

public class MyMDB implements MessageListener
public void onMessage(Message message)
TextMessage textMessage = (TextMessage) message;
try {
System.out.println("nnt(mdb) MyMDB Received n"+ textMessage.getText());
catch (JMSException e)

Step 2). Compile the Above MDB class and then create a JAR out of it.

javac    –d    .

jar   -cvf     mdb30.jar   ejb30

Step 3). Now Logic to WebLogic Admin console and create a ConnectionFactory with JNDI Name “QCF” and a Queue with JNDI Name “TestQ”.

Step 4). Deploy the MDB Jar (mdb30) file on the Server.

Step 5). Now start Writing the Client Queue Sender Program which is going to send some JMS messages to the TestQ and as a listener the MDB is going to consume these JMS messages.

import java.util.Hashtable;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QueueSend
// Defines the JNDI context factory.
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";

// Defines the JMS context factory.
public final static String JMS_FACTORY="QCF";

// Defines the queue.
public final static String QUEUE="TestQ";

private QueueConnectionFactory qconFactory;
private QueueConnection qcon;
private QueueSession qsession;
private QueueSender qsender;
private Queue queue;
private TextMessage msg;

public void init(Context ctx, String queueName)    throws NamingException, JMSException
qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
qcon = qconFactory.createQueueConnection();
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (Queue) ctx.lookup(queueName);
qsender = qsession.createSender(queue);
msg = qsession.createTextMessage();

public void send(String message,int counter) throws JMSException {
msg.setIntProperty("counter", counter);

public void close() throws JMSException {

public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Usage: java QueueSend WebLogicURL");
InitialContext ic = getInitialContext(args[0]);
QueueSend qs = new QueueSend();
qs.init(ic, QUEUE);

private static void readAndSend(QueueSend qs)    throws IOException, JMSException
String line="Test Message Body with counter = ";
for(int i=0;i<10;i++){
System.out.println("JMS Message Sent: "+line+i+"n");

private static InitialContext getInitialContext(String url)    throws NamingException
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, url);
return new InitialContext(env);


Step 6). Compile the above program and then run it.

javac        –d     .

java    QueueSend   t3://localhost:7001

Step 7). Now in Admin Console Go to the Monitoring Tab of the JMS Queue and see how many messages are getting consumed by MDB and how many messages are pending in the queue.


Jay SenSharma

Copyright © 2010-2012 Middleware Magic. All rights reserved. |