4 Replies Latest reply on Feb 10, 2009 3:39 AM by schausson

    My MdB receives the same message again and again

    schausson

      I'm currently setting up a MdB that is in charge of long-running processes :
      basically, when it receives a message, it might cause many objects (up to thousands) to be persisted in the database, which can last dozens of minutes in some cases.

      When this process lasts less than 5 minutes (approximately), everything works fine.
      When this process lasts more than 5 minutes, onMessage() is invoked again (with redelivery_count increase) and the previous processing stops without any warning/logs !

      I first suspected that it was a transaction timeout issue, and added following annotations on the onMessage() method of the MdB :
      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      @TransactionTimeout(value=100000)

      (I also tried to set a NOT_SUPPORTED transaction mode, but the entityManager (container injected one) just failed to persist my object outside of any transactional context)

      I also tried to remove the code that invoke the entityManager to isolate from DB issues.

      Finally, it always behaves in the same manner and I couldn't figure out what I can change to make it work...

      Any idea ?

      Many thanks,

      Sebastien

        • 1. Re: My MdB receives the same message again and again
          schausson

          I forgot to make clear some basics :

          I use jboss-4.2.0.GA
          My message producer sends a single message to a dedicated queue, that's why I would like to view my message processed once :)

          • 2. Re: My MdB receives the same message again and again
            jaikiran

            Looks like a transaction timeout issue. So assuming that you used org.jboss.annotation.ejb.TransactionTimeout annotation (for JBoss-4.x), the timeout shouldn't have occured. How long does the processing take? And after increasing the timeout, does it fail again after 5 minutes or does it fail after the 'x' seconds that you have set?

            Also please post appropriate logs which show this behaviour and also relevant piece of code where you are processing the message and persisting it.

            While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Please use the Preview button to ensure that your post is correctly formatted.

            • 3. Re: My MdB receives the same message again and again
              schausson

              The processing might take from a few seconds to dozens of minutes, depending on the message content...

              But to reply to your question, even with the org.jboss.annotation.ejb.TransactionTimeout annotation (I specified 100000 seconds just to give it a try), the processing stops after 'about' 5 minutes...

              The full code of my onMessage() method :
              /**
              * {@inheritDoc}
              */
              @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
              @TransactionTimeout(value=100000)
              public void onMessage(Message arg0)
              {
              final ObjectMessage om = (ObjectMessage)arg0;
              try {
              System.out.println("received message : " + arg0);
              final MyParameter plp = (MyParameter)om.getObject();
              myProcessingMethod(plp); // This method might take dozens of minutes...
              } catch (JMSException e) {
              logger.logError(e);
              } catch (Exception e) {
              System.out.println("#############################################################################");
              e.printStackTrace();
              }

              }



              By the way, I also tried to implement the callback method setMessageDrivenContext(MessageDrivenContext) to store the context in a Mdb field so that I can check ctx.getRollbackOnly(), but it seems that the container does not invoke this method ... Did I miss something here as well ?

              • 4. Re: My MdB receives the same message again and again
                schausson

                Well I finally made it work by moving most of my processing code in a SLSB that is invoked from my MdB, and for which I can tune transactions : I set a 100000 seconds timeout on the entry point method, and set a REQUIRES_NEW transaction attributes on other methods to split my processing in multiple 'small' transactions.

                As a conclusion, the issue was following :
                1 - transaction timeout seems to be not supported for MdB
                2 - REQUIRES_NEW is unavailable for MdB methods and does not allowed me to break my long-running process into multiple transactions.


                PS : The messageDrivenContext can be injected using the @Resource annotation (instead of overriding the setter method (EJB2.X old way...) that was not called by the container anyway)