2 Replies Latest reply on Feb 18, 2011 10:36 PM by cdollar393

    MDB calling EJB -- Message redelivery question

    cdollar393

      Here is my scenario: I have an .ear application with a security domain. One of the EJB3 beans puts a JMS message on a queue as part of its operation. That JMS message is consumed by a MDB, which in turn calls a different EJB3 method as part of its onMessage() method.

       

      The EJB that gets called by the MDB looks something like this:

       

      {code}

      @Stateless

      @SecurityDomain("MySD")

      public class SomeEJB implements SomeInterface {

      ...

           @RolesAllowed({"admin"})

           public void foo() {

           ...

           }

      {code}

       

      Nothing very special there. The MDB that calls this EJB looks like:

       

      {code}

      @MessageDriven(activationConfig =

      {

        @ActivationConfigProperty(propertyName="destinationType",

                                    propertyValue="javax.jms.Queue"),

        @ActivationConfigProperty(propertyName="destination",

                                    propertyValue="queue/fooQueue")

      })

      @SecurityDomain("MySD")

      @RunAs("admin")

      public class PaymentCaptureProcessorBean implements MessageListener {

           public void onMessage(Message arg0) {

                // do an EJB lookup and call foo()

           ...

      {code}

       

      There's nothing too fancy there either. This setup works fine, just as expected.

       

      Here's my question... in my MDB if I change @RunAs("admin") to @RunAs("normalUser") (so I've coded an obvious mistake by telling the MDB to run as a role that ultimately is not allowed to call the EJB method) then when the MDB goes to call the EJB foo() method I get these exceptions:

       

      {code}

      15:27:45,350 ERROR [org.jboss.ejb3.tx2.impl.CMTTxInterceptor] javax.ejb.EJBAccessException: Caller unauthorized

      15:27:45,350 ERROR [org.hornetq.ra.inflow.HornetQMessageHandler] Failed to deliver message: javax.ejb.EJBAccessException: Caller unauthorized

      {code}

       

       

      I expect this behavior too. But what I'm also seeing in this case is the MDB now continues to try to consume the message over and over again in an endless loop. I added some code to check getJMSRedelivered() and that returns false for each message that tries to be re-consumed.

       

      This makes me think that the issue is not with HornetQ (if it was I would expect getJMSRedelivered() to return true, and in that case if I saw more than 10 re-delivery attemtps then I would suspect this to be an issue with HornetQ), but since getJMSRedelivered() always returns false it seems like this isn't a true message re-delivery, but more like its trying the initial delivery over and over again.

       

      Now granted I clearly coded in error, but the effect of the endless loop of the MDB getting the message trashes the server so hard that the only thing to do to get it to stop is to shut it down.

       

      So is this expected behavior?

       

      Thanks!

      Chris