Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Message Bean

Although the entity bean can be fairly complex, the session bean is simpler, and the message bean tags are simpler still. First, the example bean:

package com.dzrealms.example.entity;

import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.jms.MessageListener;
import javax.jms.Message;

/**
 * @ejb.bean name="ExampleMessage"
 *      destination-type="javax.jms.Queue"
 *
 * @jboss.destination-jndi-name name="queue/ExampleQueue"
 */
public class ExampleMessageBean implements MessageDrivenBean, MessageListener {

 /**
  * @ejb.create-method
  * @throws CreateException
  */
  public void ejbCreate() throws CreateException {

  }

  public void setMessageDrivenContext(MessageDrivenContext context) {
  }

  public void ejbRemove() throws EJBException {
  }

  public void onMessage(Message message) {
  }
}

That is the entire bean. The only definitions required for a message bean include naming it, defining what kind of messaging it handles and naming the queue/topic. There is nothing else to define for a message bean other than tagging the create.

  • + Share This
  • 🔖 Save To Your Account