Example of Message Driven Bean, MCS51-june2007-3(ii)

Simple example for the MDB without configuration file. 
package mdb;

import javax.ejb.*;
import javax.jms.*;
import javax.naming.*;

public class MyMDB implements MessageDrivenBean, MessageListener
{

  public MyMDB()
  {

  }
//invoked first after ejbCreate() of MDB

  public void setMessageDrivenContext(MessageDrivenContext mdc)
  {
  }

//invoked first after just object creation of MDB
  public void ejbCreate()
  {
    System.out.println("ejbCreate(): " + this);
  }
//this method is invoked when any message arrives on the destination for which this MDB has been configured. 

  public void onMessage(Message inMessage)
  {

    try
    {
      System.out.println("Message received: " + inMessage);
    } catch (Exception e)
    {
      e.printStackTrace();
    }
  }
//this method invoked when MDB object being destroyed by EJB server

  public void ejbRemove()
  {
    System.out.println("ejbRemove(): " + this);
  }
}

No comments:

Popular Posts