6 Replies Latest reply on May 11, 2009 12:56 PM by Yong Hao Gao

    about transaction and order

    Scott Zhang Newbie

      In my case, ineed to process message by order, so i create a Session Bean (Processor) to do that, the code is like following:

      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public boolean process() throws BusinessException {
      try {
      Message message = poll();
      if (message != null) {
      handle(message);
      return true;
      }
      } catch (Exception e) {
      logger.error("error", e);
      throw new BusinessException(e);
      }
      return false;
      }

      in the function poll(), i just create a MessageConsumer and call receive()。
      in another job, call this session bean like this:

      processor.open();
      try {
      while (processor.process())
      ;
      } finally {
      processor.close();
      }

      and in open() function, i create connection and session, and in close() function i close them.

      In my test, we put 10 messages into the queue, and the 5th one will process failed.
      I found several strange problems:
      1�messages after the 5th one was processed
      2�there are 2 messages left, one is the 5th

      How to explain these?

      And how to receive 1, 2, 3, 4, and then blocked.

        • 1. Re: about transaction and order
          Scott Zhang Newbie

          I found several strange problems:
          1 €�messages after the 5th one was processed
          2 €�there are 2 messages left, one is the 5th

          • 2. Re: about transaction and order
            Yong Hao Gao Master

            Hi, some of the characters are not readable. Can you re-format?
            Also please state the version of the JBM, and how you send the messages. Thanks.

            • 3. Re: about transaction and order
              Scott Zhang Newbie

              I found several strange problems:
              1 messages after the 5th one was processed
              2 there are 2 messages left, one is the 5th

              My version is jboss-messaging-1.4.2.GA-SP1。

              • 4. Re: about transaction and order
                Scott Zhang Newbie

                In my case, I need to process message by order, so I create a Session Bean (Processor) to do that, the code is like following:

                @TransactionAttribute(TransactionAttributeType.REQUIRED)
                public boolean process() throws BusinessException {
                 try {
                 Message message = poll();
                 if (message != null) {
                 handle(message);
                 return true;
                 }
                 } catch (Exception e) {
                 logger.error("error", e);
                 throw new BusinessException(e);
                 }
                 return false;
                }
                


                in the function poll(), I just create a MessageConsumer and call receive().
                In another job, call this session bean like this:

                processor.open();
                try {
                 while (processor.process())
                 ;
                } finally {
                 processor.close();
                }
                


                and in open() function, i create connection and session, and in close() function i close them.

                In my test, first put 10 messages into the queue, and the 5th will throw a exception in process.
                I found strange problems:
                1. messages after the 5th one was processed, i.e. some of 6, 7, 8, 9, 10 was processed
                2. there are 2 messages left, one is the 5th, another is any of 6, 7, 8, 9, 10

                How to explain these?

                And how to receive 1, 2, 3, 4, and then blocked.

                My version jboss-messaging-1.4.2.GA-SP1.
                The following is the code to send message:
                 Connection connection = factory.createConnection();
                 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                 MessageProducer pub = session.createProducer(topic);
                 ObjectMessage msg = session.createObjectMessage();
                 msg.setObject(cmd);
                 pub.send(msg);
                 pub.close();
                 session.close();
                 connection.close();
                



                • 5. Re: about transaction and order
                  Scott Zhang Newbie

                  Anybody can help me?
                  Or I must be waiting for the next GA version to solve this problem?