1 Reply Latest reply on Apr 23, 2013 5:09 PM by rhinmass

    MDB onMessage firing before it's dependency

    rhinmass

      My Jboss 7 application has a startup singleton, which sets up the datasource, configures hibernate, etc.

       

      This  looks like:

       

      @Singleton

      @Startup

      public class EjbAppContext

      {

       

        @PostConstruct

        public void init()

        {

           //Initialize the application context

          AppContext.init();

        }

      }

       

       

      My MDB injects this singleton, as a way (or so I thought) of establishing a dependency:

       

      @Inject EjbAppContext ejbAppCtx;

       

      public void onMessage(Message msg) {

       

           //Process the messag

           //In here, I get errors because AppContext.init() below is not finished

      }

       

       

      This works fine when the hornetq data is empty when the container starts up.  But if there are messages sitting in the queue at startup I get errors that lead me to believe that AppContext.init() has not yet finished.

       

      specifically:

       

      15:41:15,815 ERROR [org.jboss.ejb3.invocation] (Thread-0 (HornetQ-client-global-threads-1472661282)) JBAS014134: EJB Invocation failed on component QueueListener0 for method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message): javax.ejb.EJBTransactionRolledbackException: AppContext has not been initialized.

       

      Is there a way to prevent message delivery until the injected class has been fully initialized?

       

      I had previously solved this in Jboss 6 by configuring queues in ejb-jar.xml  with DeliveryActive set to false, and then turning them on after AppContext.init() is called. However, that parameter is not supported in the current version of jboss/hornetq.  (7.1.1/2.2.13)

       

      It seems DependsOn or Depends annotations are not available either.

       

      I have also tried NOT injecting the ejbAppCtx, since it is not actually used by the MDB.  Still, even though annotated as a startup singleton, messages are still being delievered to my MDB before the singleton is completed postConstruct.

       

      Any ideas? Is this a bug?  Is there a work around?

       

      Thanks!!

      Robin