0 Replies Latest reply on Apr 26, 2006 5:35 AM by saravanan thangarasu

    my MDB is not invoked by jboss container

    saravanan thangarasu Newbie

      Hi

      Here i am deployed MyMDB.jar under the jboss deploy folder...
      and i am running the jms client...client is working good..But my MDB is not working ..what may be the reason..

      please advice me

      This is my client

      public class MessageSender {
      public static void main(String[] args) {
      QueueConnection queueConnection = null;

      try {

      Hashtable props = new Hashtable();
      props.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      props.put(Context.PROVIDER_URL, "localhost:8080/");
      props.put("java.naming.rmi.security.manager", "yes");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");

      Context context = new InitialContext(props);
      QueueConnectionFactory queueConnectionFactory =
      (QueueConnectionFactory) context.lookup("QueueConnectionFactory");
      System.out.println("queueConnectionFactory ----"+queueConnectionFactory );
      String queueName = "MyQueue";
      Queue queue = (Queue) context.lookup("queue/MyQueue");

      System.out.println("queue----"+queue);
      queueConnection =
      queueConnectionFactory.createQueueConnection();

      System.out.println("queueConnection ----"+queueConnection );
      QueueSession queueSession =
      queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = queueSession.createSender(queue);
      TextMessage message = queueSession.createTextMessage();
      message.setText("This is a TextMessage");
      queueSender.send(message);
      System.out.println("Message sent.");
      }
      catch (NamingException e) {
      System.out.println("Naming Exception : " );
      e.printStackTrace();
      }
      catch (JMSException e) {
      System.out.println("JMS Exception");
      }
      finally {
      if (queueConnection != null) {
      try {
      System.out.println("finally closing the connection");
      queueConnection.close();
      }
      catch (JMSException e) {}
      }
      }
      }

      }


      This is my BEAN......
      MessageDrivenContext context = null;
      QueueConnection connection;
      QueueSession session;

      public MyMDB() {
      System.out.println("Constructing MyMDB");
      }

      public void setMessageDrivenContext(MessageDrivenContext context) {
      this.context = context;
      System.out.println("setMessageDrivenContext");
      }

      public void ejbCreate() throws EJBException {
      System.out.println("ejbCreate");
      try {
      InitialContext initContext = new InitialContext();
      QueueConnectionFactory qcf = (QueueConnectionFactory)
      initContext.lookup("java:comp/env/jms/QCF");
      connection = qcf.createQueueConnection();
      session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      connection.start();
      }
      catch(Exception e) {
      throw new EJBException("Failed to initialize MyMDB", e);
      }
      }

      public void ejbRemove() {
      System.out.println("ejbRemove");
      context = null;
      try {
      if( session != null )
      session.close();
      if( connection != null )
      connection.close();
      }
      catch(JMSException e) {
      e.printStackTrace();
      }
      }

      public void onMessage(Message msg) {
      System.out.println("onMessage");
      try {
      TextMessage message = (TextMessage) msg;
      Queue queue = (Queue) msg.getJMSReplyTo();
      QueueSender sender = session.createSender(queue);
      TextMessage message2 = session.createTextMessage(message.getText());
      sender.send(message2);
      sender.close();
      }
      catch(Exception e) {
      e.printStackTrace();
      }
      }



      This is my ejb-jar.xml


      <?xml version="1.0"?>
      <!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>MyMDB</ejb-name>
      <ejb-class>com.nabil.ejb.MyMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      <resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>


      This is my jboss.xml...

      <?xml version="1.0" encoding="UTF-8"?>

      <enterprise-beans>
      <message-driven>
      <ejb-name>MyMDB</ejb-name>
      <destination-jndi-name>queue/MyQueue</destination-jndi-name>
      <resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <jndi-name>QueueConnectionFactory</jndi-name>
      </resource-ref>
      </message-driven>
      </enterprise-beans>



      my jar structure is...

      added manifest
      com/nabil/ejb/MyMDB.class
      META-INF/ejb-jar.xml
      META-INF/jboss.xml

      ....Please advice me what i have to do to run my MDB...