4 Replies Latest reply on Dec 14, 2015 12:51 PM by gberish

    How do I limit number of tries my MDB onMessage() method makes before giving up?

    gberish

      Hi,

       

      I know I can limit the number of times the container tries to execute my MDB onMessage() method with rollbacks, I just can't find how to do it.  Can anyone help?

       

      "When you are up to your arm pits in alligators, it's hard to remember your there to drain the swamp."

      In my case, I need to figure out why a Session Bean method called by my MDB won't persist my Entity

      ... but with onMessage() generating 20 rollbacks and retries to flood the log, I need to drain that swamp first.

       

      Here's the rest of the detail:

       

      I can tell from output my code writes to server.log that:

      -- The MDB is being called,

      -- A Session Bean is successfully injected as an MDB member, and.

      -- The MDB reads the JMS message, prepares a reply, and sends it to a Queue successfully.

            This is the last line from my MDB that successfully sends a reply:

           this.jmsCtx.createProducer().send(this.svrSendQueue, replyMsg);

             if I allowed the MDB to return at that point, all works well and the java client that sent the first message receives a reply..

       

      But I have code immediately following send() that invoke a method on the Session Bean -- process().  If I un-comment that line, the container tries to execute onMessage() 20 more times and each time writes the same errors and stack traces to flood server.log with endless errors.

       

      When the line calling process() on the Session Bean is un-commented, I can tell from what my code writes to server.log that

      --  everything through send() in onMessge still executes without error,

      --  process() is in fact invoked in the Session Bean,

      --  an Entity is successfully instantated in process() w/info passed to it from onMessage() taken from the original message,

      --  and then process throws and Exception while trying to persist the entity

      The container fills server.log with a set 1 of a long error list and stack trace.

       

      Then onMessage() starts all over again.

      -- it read the original message, Creates a reply message, executes send() again.

      -- it invokes process() again which fails again.

      The container fills server.log with a set 2 of a long error list and stack trace.

       

      etc. 18 more times.

       

      I have a try-catch block around the em.persist() line in process.

       

      My MDB onMessage() has two try-catch blocks.

      -- on encloses all code through and includoing send,

      -- a 2nd one encloses this.bean.process();

        • 1. Re: How do I limit number of tries my MDB onMessage() method makes before giving up?
          jbertram

          I know I can limit the number of times the container tries to execute my MDB onMessage() method with rollbacks, I just can't find how to do it.  Can anyone help?

          Assuming you're using a version of Wildfly that has HornetQ as the JMS implementation you can refer to the HornetQ documentation for the configuration details you need.  Look for "max-delivery-attempts".

           

          Keep in mind that the MDB's onMessage operates within a JTA transaction by default and any additional transactional operation that is performed within the onMessage (e.g. sending a JMS message) will also be enlisted in that same transaction.  If onMessage throws a RuntimeException then its transaction will be rolled back and any work done within the transaction will not actually complete.

          1 of 1 people found this helpful
          • 2. Re: How do I limit number of tries my MDB onMessage() method makes before giving up?
            gberish

            Hi Justin,

             

            I understand the concept.  But the container not  only rolls back the failed transaction.  It runs onMessage() 19 more times, and because its using the same code and same message data, it throws the same darn exception. 19 more times.

             

            And each time that happens, it floods the log with another set of WF Error messages followed by a huge stack trace til the output overflows my console buffer ... and makes the log a nightmare to read and sort out.

             

            So I'd really like to set the container so it only tries once before it gives up .

            .. not rerun the same error 20 times.

             

            I once found a way to do that on Glassfish, but having moved to WF I'm not sure how to do it.  Hope someone out there can tell me.

            • 3. Re: How do I limit number of tries my MDB onMessage() method makes before giving up?
              jbertram

              So I'd really like to set the container so it only tries once before it gives up .

              .. not rerun the same error 20 times.

               

              I once found a way to do that on Glassfish, but having moved to WF I'm not sure how to do it.  Hope someone out there can tell me.

              I guess I'm a bit confused.  Did you read my last comment?  I said, "...you can refer to the HornetQ documentation for the configuration details you need.  Look for 'max-delivery-attempts'."

              • 4. Re: How do I limit number of tries my MDB onMessage() method makes before giving up?
                gberish

                Justin,

                 

                My sincere apologies.  I have no idea how I failed to read your first paragraph above, but I did.

                 

                Not only does your source solve my problem its a great source of info on managing Queues.  Thanks.