5 Replies Latest reply on May 8, 2002 11:56 AM by Jonathan O'Connor

    MDB only consumes at startup on JBoss3 Alpha

    Jonathan O'Connor Newbie

      Folks,
      After 3 days of bashing my brains, I now have a session bean that correctly sends messages to a queue. I used all the managed resource stuff. And it seems to work fine.

      But my MDB only runs onMessage() at startup when there are old messages in the queue to be processed.

      If my session bean generates more messages on the queue (and yes they do go into the db/jbossmq/file/QUEUE.myQueue folder), I get the following exception in the log:
      [2002-04-30 12:48:38,797,ClientConsumer:ID2,WARN] Could not send messages to a receiver.
      javax.jms.JMSException: Unsupported priority: priority must be from 0-10
      at org.jboss.mq.SpyMessage.setJMSPriority(SpyMessage.java:179)
      at org.jboss.mq.SpyMessage.copyProps(SpyMessage.java:464)
      at org.jboss.mq.SpyMapMessage.myClone(SpyMapMessage.java:377)
      at org.jboss.mq.il.jvm.JVMClientIL.receive(JVMClientIL.java:87)
      at org.jboss.mq.server.ClientConsumer.doWork(ClientConsumer.java:230)
      at org.jboss.mq.threadpool.ThreadPool$WorkerThread.run(ThreadPool.java:230)

      Any ideas why I get this?
      Ciao,
      Jonathan O'Connor

        • 1. Re: MDB only consumes at startup on JBoss3 Alpha
          Jonathan O'Connor Newbie

          Here's some extra information:

          1. I don't do anything with the priority of the message.

          2. The relevant part of ejb-jar.xml for my message bean is:
          <message-driven >
          <ejb-name>AdviceHandler</ejb-name>
          <ejb-class>xcom.traxbahn.bproc.bcomponents.ejb.AdviceHandlerMsgBean</ejb-class>
          <transaction-type>Container</transaction-type>
          <message-driven-destination>
          <destination-type>javax.jms.Queue</destination-type>
          </message-driven-destination>
          </message-driven>

          3. The relevant part of jboss.xml for the message bean is:
          <message-driven>
          <ejb-name>AdviceHandler</ejb-name>
          <destination-jndi-name>queue/AdviceHandler</destination-jndi-name>
          <configuration-name>Standard Message Driven Bean</configuration-name>
          </message-driven>

          4. My message sending session bean works correctly. After every message that is sent to the queue, I can see a new file in db/jbossmq/file/QUEUE.AdviceHandler.

          5. For some reason, my MDB only processes these messages when JBOSS is started and my EAR is deployed. (Probably happens when the EAR is deployed. Once the EAR is deployed, any messages generated after this are ignored, and I get the exception listed in my first message.

          6. Yes, I do know I should move to RC1, but this will involve a fair amount of work because of the change in DTD formats for entity beans.

          Thanks for your attention,
          Jonathan

          • 2. Re: MDB only consumes at startup on JBoss3 Alpha
            Hiram Chirino Expert

            What's your jbossmq version???

            test putting a message to the MDB's queue with a standalone jms application. Maybe the transaction handling in the session bean is messed up.

            If that's not the problem, please submit your bean so that I can test it out on my system.

            • 3. Re: MDB only consumes at startup on JBoss3 Alpha
              Jonathan O'Connor Newbie

              I don't know what the jbossmq version is. Its whatever came as standard with 3.0 Alpha version. (I seem to think this is logged at startup time).

              As its a bank holiday here on Monday, it'll be a few days before I can try your suggestions out.

              You could be right about the session beans transaction handling.

              Thanks,
              Jonathan

              • 4. Re: MDB only consumes at startup on JBoss3 Alpha
                Jonathan O'Connor Newbie

                OK, I wrote a test program and ran it on JBoss RC2 with no changes to the configuration (Its straight out of the box)

                Sadly, I get no errors from my test program. It says it has posted the message directly. However, I don't see any messages kept in {JBOSS_HOME}\server\default\db\jbossmq\file\QUEUE.testQueue

                Here's my code - apologies for no indentation as web site seems to cut those out:

                /*
                * TestAdviceHandler.java
                *
                * Created on 07 May 2002, 17:50
                */

                package traxbahn.test;

                import javax.ejb.EJBException;
                import javax.jms.JMSException;
                import javax.jms.MapMessage;
                import javax.jms.Queue;
                import javax.jms.QueueConnection;
                import javax.jms.QueueConnectionFactory;
                import javax.jms.QueueSender;
                import javax.jms.QueueSession;

                import javax.naming.Context;
                import javax.naming.InitialContext;
                import javax.naming.NamingException;

                /**
                * This class is a test program for the Advice Handler MDB.
                * It sends a single message to theAdviceHandlerQueue
                *
                * @author joconnor
                */
                public class TestAdviceHandler {
                private static final String STANDARD_QUEUE_FACTORY_NAME = "ConnectionFactory";
                private static final String STANDARD_QUEUE_NAME = "queue/testQueue";

                /** Creates a new instance of TestAdviceHandler */
                public TestAdviceHandler() {
                }
                public static void main( String[] args ) {
                QueueConnection connection = null;
                QueueSession session = null;
                QueueSender sender = null;

                try {
                Context ctx = new InitialContext();
                QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup( STANDARD_QUEUE_FACTORY_NAME );
                Queue queue = (Queue) ctx.lookup( STANDARD_QUEUE_NAME );
                connection = factory.createQueueConnection();
                session = connection.createQueueSession( true, QueueSession.AUTO_ACKNOWLEDGE );
                sender = session.createSender( queue );
                MapMessage msg = session.createMapMessage();
                byte[] bytes = new byte[100];
                bytes[0] = (byte)'9';
                bytes[1] = (byte)'9';
                bytes[1] = (byte)'9';
                bytes[1] = (byte)'9';
                msg.setBytes( "RawMsg", bytes );
                sender.send( msg );
                System.out.println( "Message sent to " + STANDARD_QUEUE_NAME );

                } catch ( Exception e ) {
                e.printStackTrace();
                } finally {
                try {
                if ( sender != null )
                sender.close();
                } catch ( Exception e ) {
                e.printStackTrace();
                }

                try {
                if ( session != null )
                session.close();
                } catch ( Exception e ) {
                e.printStackTrace();
                }

                try {
                if ( connection != null )
                connection.close();
                } catch ( Exception e ) {
                e.printStackTrace();
                }
                System.out.println( "Everything closed" );
                }
                }
                }

                Any reason why this won't work. I also tried the same test program on my JBoss 3 alpha system, and it too didn't do anything.

                Ciao,
                Jonathan

                • 5. Re: MDB only consumes at startup on JBoss3 Alpha
                  Jonathan O'Connor Newbie

                  Well,
                  It seems my problems were all caused by creating the session with true and not false. I don't know why this is so, but it is!

                  // BAD CODE - CAUSES FAILURE
                  session = connection.createQueueSession( true, QueueSession.AUTO_ACKNOWLEDGE );

                  // GOOD CODE - MAKES SYSTEM WORK
                  session = connection.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );

                  Sorry to bother everyone.
                  Ciao,
                  Jonathan