Search This Blog

Monday, 16 November 2015

Message Driven Bean (EJB 3.0) deployment

JMS Server, Module creation you can refer the previous posts.
This program requires the JMS Module configurations

Configuration of JMS Module for MDB
Sample JMS Module configuration for different types of JMS destinations

We can use any kind of JMS destinations in the MDB program. Here in the sample program we are going to use the Queue, where we will refer to its JNDI name is jms.test.TestQ1.

Create a Message Driven Bean (MDB) 3.0


This sample is for Admins and WebLogic based developers. Now open a editor and write the following Java code:

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;

@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") ,
@ActivationConfigProperty(propertyName="connectionFactoryJndiName",propertyValue="jms.test.QCF"),
@ActivationConfigProperty(propertyName="destinationJndiName", propertyValue="jms.test.TestQ")
}
,mappedName="jms.test.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)
{
e.printStackTrace();
}
}
}

Note: The ConnectionFactory, Queue JNDI names must match to your configured on the WebLogic admin console.

Compile the MDB Code

This is regular process of Java program compilation, -d option used to create the package directory, dot indicate current location path and a Java file.

javac -d . MyMDB.java

Generate MDB Jar

Now lets generate the artifact which we can deploy on WebLogic platform

jar   -cvf     mdb30.jar   ejb30     MyMDB.java

Deploying  MDB application on WebLogic

Goto your WebLogic admin console select deployments select install and select the path where the mdb30.jar file created. then do the deploy the artifact.

WebLogic Deployment for MDB
MDB Deployment on WebLogic Cluster


Running QueueSend

All set to go!! Execute the QueueSend program to send messages to the MDB, which is listening on the WebLogic cluster/server.

java jms.test.QueueSend t3://192.168.33.100:7011
 
QueueSend to MDB

MDB Listening

 tail -100f ms1.out
 

Finally you can see the received messages in the Managed server output log. That confirms JMS capabilities.

No comments:

Post a Comment

WebLogic Books

  • Oracle WebLogic Server 12c: Administration Handbook
  • WebLogic Diagnostic Framework
  • Advanced WebLogic Server Automation
  • Oracle SOA Suite 11g Administrator's Handbook

Popular Posts