5 Replies Latest reply on Mar 3, 2002 3:46 AM by jayeshpk

    No callback from a queue to MDB onMessage()

    twhphan

      I'm trying to use a MDB to consume a queue, queue/mailer. After deploying it, JBoss doesn't report any error. Then I execute my sender; the sender doesn't give any exception, and I see a connection to my JMS server port 8090 (by using netstat) However, I don't see the JMS calls the onMessage method. What can go wrong? And how may I know more information to debug?

      I did the same thing to another bean using javax.jms.Topic, and topic works fine.

      The MDB
      /**
      * @ejb:bean name="Mailer" transaction-type="Container" acknowledge-mode="Auto-acknowledge" destination-type="javax.jms.Queue"
      * @ejb:resource-ref res-name="mail/MailSession" res-type="javax.mail.Session" res-auth="Container"
      *
      * @jboss:destination-jndi-name "queue/mailer"
      * @jboss:resource-manager res-man-name="mail/MailSession" res-man-jndi-name="java:/Mail"
      */
      public class MailerBean implements MessageDrivenBean, MessageListener {
      public void onMessage(Message message) {
      System.out.println("A");
      ...
      }
      }

      the sender (client) code:
      public void sendMail(String xmlMail) throws JMSException {
      QueueConnection connection = null;
      try {
      connection = factory.createQueueConnection();
      QueueSession session = connection.createQueueSession(true, 0);
      connection.start();
      QueueSender sender = session.createSender(queue);
      TextMessage message = session.createTextMessage();
      message.setText(xmlMail);
      sender.send(message);
      }
      finally {
      try {
      if( connection != null ) { connection.close(); }
      }
      catch(Exception e) {}
      }
      }

      where,

      factory = (QueueConnectionFactory) ctx.lookup("java:/ConnectionFactory");
      queue = (Queue) ctx.lookup("queue/mailer");

        • 1. Re: No callback from a queue to MDB onMessage()

          Have you turned on debug or even and looked in the logfiles?

          What is your code doing after println, may it throw an exception there - it's been seen before ;-)

          //Peter

          • 2. Re: No callback from a queue to MDB onMessage()
            twhphan

            Thanks Peter

            I enabled debug, and got:

            2002-03-03 01:34:22,608 DEBUG [org.jboss.mq.il.oil.OILClientIL] ConnectionReceiverOILClient is connecting to: <my sender's IP>:

            on the server each time after I called sendMail() on the client, but still don't see the println() message

            Since println("A") is the first line of onMessage(), even if the code after that throws an exception, the server should still prints the "A" [note: i added more println() stmts in the onMessage(), but none of them prints]

            public void onMessage(Message message) {
            System.out.println("A");
            try {
            MailerData mailerData;
            if (message instanceof TextMessage) mailerData = MailerData.fromXML(((TextMessage) message).getText());
            else if (message instanceof ObjectMessage) mailerData = (MailerData) ((ObjectMessage) message).getObject();
            else return;
            try { mailerData.toXML(System.out); } catch (Exception e) {}
            Category.getInstance(getClass().getName()).debug("receive mail content=\n" + mailerData.getContent());
            (new MailHelper()).sendMail(mailerData.getFrom(), mailerData.getTo(), mailerData.getCc(), mailerData.getBcc(), mailerData.getSubject(), mailerData.getContent(), mailerData.getContentType());
            }
            catch (MailerAppException mae) {
            //throw new EJBException("MailerMDB.onMessage" + mae);
            //ignore since user probably forgot to set up mail server
            }
            catch (XMLDocumentException xmlde) { throw new EJBException("MailerBean.onMessage" + xmlde); }
            catch (JMSException jmse) { throw new EJBException("MailerBean.onMessage" + jmse); }
            }

            • 3. Re: No callback from a queue to MDB onMessage()

              Hi, its truly hard to say what it might be. This has worked for over a year now, and you don't get anu exceptions. Arev you really publishing to the same queue you are listening on ;-)

              //Peter

              • 4. Re: No callback from a queue to MDB onMessage()
                twhphan

                Hi, thanks again

                Yes, the same queue


                <depends optional-attribute-name="JBossMQService">jboss.mq:service=Server


                and queue/mailer shows up in the JMX RI/1.0 Agent View (http port 8082)... Have I missed setting something?

                • 5. Re: No callback from a queue to MDB onMessage()
                  jayeshpk

                  Thats what debuggers are for. Try Eclipse, jbuilder or forte. All of them are free. Also check again to see if your mail server is up and running.

                  Good luck.

                  Jayesh