3 Replies Latest reply on Oct 5, 2005 12:51 AM by aycanirican

    MDB and Session Bean dependency

    aycanirican Newbie

      Hello,

      I have a MDB and a session bean. I Injected resources to my session bean to send messages:

      @Resource(name = "ConnectionFactory")
      QueueConnectionFactory factory;
      
      @Resource(name = "queue/ticket")
      Queue queue;
      


      But while deploying the ear, I got
      javax.naming.NameNotFoundException: queue not bound

      This is because Jboss loads Session beans before the MDBs, so that the queue doesn't created yet. How can I define this type of dependency, so that the MDB loads first.

      Thank you.


        • 1. Re: MDB and Session Bean dependency
          aycanirican Newbie

          Manual lookup is a workaround, but I'm waiting for a fix.

          InitialContext ctx = new InitialContext();
          Queue queue = (Queue) ctx.lookup("queue/ticket");
          QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
          QueueConnection cnn = factory.createQueueConnection();
          QueueSession sess = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
          ObjectMessage msg = sess.createObjectMessage();
          


          Thank you.

          • 2. Re: MDB and Session Bean dependency
            Bill Burke Master

            still have a lot of work to do in dependency management. I suggest creating the queue statically through XML rather than having the MDB create it. Deploy this XML separately from the EAR.

            Can you explain your exact deployment? The structure of your EAR where you are defining the queue, etc...

            Thanks.

            • 3. Re: MDB and Session Bean dependency
              aycanirican Newbie

              Ofcourse,

              We use jboss-4.0 CVS. Our EAR is a simple one and includes entities.par, business.ejb3 and a web module for testing with cactus(all defined in application.xml). business.ejb3 includes Session beans and a MDB.

              I defined the queue in one of our MDB's with anotations:

              @MessageDriven(activateConfig = {
               @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
               @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/ticket") })
              public class TicketConsumerMDB implements MessageListener {
              ...
              }
              


              This is because I read something like "There is no XML configuration file needed!" here:

              http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/mdb/index.html

              So the queue will be opened. This was ok.
              07:38:55,297 WARN [MDB] Could not find the queue destination-jndi-name=queue/ticket
              07:38:55,298 WARN [MDB] destination not found: queue/ticket reason: javax.naming.NameNotFoundException: ticket not bound
              07:38:55,299 WARN [MDB] creating a new temporary destination: queue/ticket
              07:38:55,338 INFO [ticket] Bound to JNDI name: queue/ticket
              


              Then I started to write a message producer facade to one of our SessionBeans. First I defined factory and queue with Resource injection and used them in a method.

              @Resource(name = "ConnectionFactory")
              QueueConnectionFactory factory;
              
              @Resource(name = "queue/ticket")
              Queue queue;
              ...
              some method
              ...
              QueueConnection cnn = factory.createQueueConnection();
               QueueSession sess = cnn.createQueueSession(false,
               QueueSession.AUTO_ACKNOWLEDGE);
               ObjectMessage msg = sess.createObjectMessage();
               msg.setObject(props);
               QueueSender sender = sess.createSender(queue);
               sender.send(msg);
              


              But I saw that the Resource injection occurs before loading of MDBs. And I'm getting this:
              07:44:13,361 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,name=tr.gen.core.accounting.RegistrationServiceBean
              javax.naming.NameNotFoundException: queue not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
               at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
               at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
               at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
               at org.jnp.server.NamingServer.lookup(NamingServer.java:255)
               at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
               at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
               at javax.naming.InitialContext.lookup(InitialContext.java:351)
               at org.jboss.ejb3.injection.ResourceHandler.loadFieldInjectors(ResourceHandler.java:182)
               at org.jboss.ejb3.injection.ResourceHandler.loadInjectors(ResourceHandler.java:125)
               at org.jboss.ejb3.EJBContainer.resolveInjectors(EJBContainer.java:394)
               at org.jboss.ejb3.EJBContainer.initializePool(EJBContainer.java:330)
               at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:283)
               at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:48)
               at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:63)
               at org.jboss.ejb3.stateless.StatelessManager.startService(StatelessManager.java:93)
               at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
               at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
               at $Proxy0.start(Unknown Source)
               at org.jboss.system.ServiceController.start(ServiceController.java:428)
               at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
               at $Proxy108.start(Unknown Source)
               at org.jboss.ejb3.Ejb3JmxDeployment.start(Ejb3JmxDeployment.java:258)
               at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:39)
               at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
               at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
               at $Proxy0.start(Unknown Source)
               at org.jboss.system.ServiceController.start(ServiceController.java:428)
               at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
               at $Proxy17.start(Unknown Source)
               at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:228)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
               at $Proxy18.start(Unknown Source)
               at org.jboss.deployment.MainDeployer.start(MainDeployer.java:989)
               at org.jboss.deployment.MainDeployer.start(MainDeployer.java:979)
               at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:790)
               at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753)
               at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
               at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
               at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
               at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
               at $Proxy9.deploy(Unknown Source)
               at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319)
               at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:489)
               at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192)
               at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203)
               at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)