3 Replies Latest reply on Aug 29, 2003 9:14 AM by ah123

    Client doesn't receive message back from MDB

    ah123 Newbie

      Hello,

      I'm new to MDB, so I tried the sample posted here, testmdb.zip. It all worked fine.
      But when I tried to add functionality such: MDB sending a message, and another class, clientListener listens to it,
      the clientListener NEVER received any message back.

      The additional changes to the code:
      In the MDB: I'm sending a message to the same queue (repeated what the client is doing).

      Created a new class to listen to the message from MDB, the onMessage methods seems is not to be called:

      package test.mdb;
      import java.util.*;

      import javax.naming.*;

      import javax.jms.*;

      /**
      * @author arielah
      *
      * To change the template for this generated type comment go to
      * Window>Preferences>Java>Code Generation>Code and Comments
      */
      public class ClientListener implements MessageListener {
      public ClientListener() throws Exception {
      QueueConnection connection = null;
      QueueSession session = null;
      try {
      InitialContext ctx = new InitialContext();

      log.info("Looking up connection");
      QueueConnectionFactory conFactory =
      (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      connection = (QueueConnection) conFactory.createQueueConnection();

      log.info("Looking up queue");
      Queue queue = (Queue) ctx.lookup("queue/testQueue");

      log.info("Creating session");
      session =
      connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver receiver = session.createReceiver(queue);
      log.info("Set message listener" + receiver);

      receiver.setMessageListener(this);
      log.info("Start");

      connection.start();



      } finally {
      if (session != null)
      session.close();
      if (connection != null)
      connection.close();
      }

      }
      public static void main(String[] args) throws Exception {
      new ClientListener();
      log.info("new ClientListner");

      while (true) {
      Thread.sleep(10000);
      }
      }

      public static class log {
      public static void info(String s) {
      System.out.println(s);
      }
      }

      /* (non-Javadoc)
      * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
      */
      public void onMessage(Message message) {
      System.out.println("onMessage called");
      //TextMessage textMessage = (TextMessage)message;
      try {
      System.out.println("From listener");
      System.out.println(message);
      } catch (Exception e) {
      log.info(e.getMessage());
      }

      }

      }