6 Replies Latest reply on Nov 4, 2005 11:38 AM by dornus

    NameNotBound for injected Queue

    Stefan Frank Newbie

      I havedeployed a Queue using:

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
       <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=myQueue">
       <attribute name="JNDIName">myQueue</attribute>
       <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
       </mbean>
      </server>
      


      and I want to inject this queue via

      @Resource (name="myQueue")
       Queue queue;
      


      I verified, that I can lookup and send Messages using

      InitialContext ctx = new InitialContext();.
      queue = (Queue) ctx.lookup("ullqueues/externalTokens");
      


      - however, when we deploy the Bean, we get an Exception:
      javax.naming.NameNotFoundException: queue not bound


      Is this supposed to work, or is there anything special to do, to make injections for queues work?!

      Cheers
      stf


        • 1. Re: NameNotBound for injected Queue
          Jens Elkner Apprentice

          Looks like you are using different names for queue setup and lookup ...

          • 2. Re: NameNotBound for injected Queue
            Stefan Frank Newbie

            oops,

            no: I just changed the name of the queue to protect the innocent, was just a typo - here is the complete setup:

            Queue:

            <?xml version="1.0" encoding="UTF-8"?>
            <server>
             <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=myQueue">
             <attribute name="JNDIName">myQueue</attribute>
             <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
             </mbean>
            </server>
            


            Resource:
            @Resource (name="myQueue")
            Queue queue;
            


            Lookup using injected sessionContext:
            @Resource
            SessionContext ctx;
            ...
            queue = (Queue) ctx.lookup("myQueue");
            


            Still, the queue gives a NameNotBound-Exception, but the lookup using the sesionContext works.



            • 3. Re: NameNotBound for injected Queue
              Jens Elkner Apprentice

              Hmmm, what does your server log say, when you try to deploy?
              Usually there should be something like:

              2005-11-02 10:55:16,749 INFO [main:org.jboss.mq.server.jmx.DestinationMBeanSupport:204] - Bound to JNDI name: myQueue
              


              E.g. I'm using
              <?xml version="1.0" encoding="UTF-8"?>
              <!-- $Id$ -->
              <server>
               <mbean code="org.jboss.mq.server.jmx.Topic"
               name="jboss.mq.destination:service=Topic,name=foo">
               <attribute name="JNDIName">topic/foo/model</attribute>
               <depends optional-attribute-name="DestinationManager"
               >jboss.mq:service=DestinationManager</depends>
               </mbean>
              </server>

              And than you should see Bound to JNDI name: topic/foo/model

              BTW: Just to be sure: your queue config file ends with "-service.xml" ?

              • 4. Re: NameNotBound for injected Queue
                Stefan Frank Newbie

                Thats exactly the problem: The Server-Log confirms, that the queue is deployed correctly, and we can send messages into the queue from both outside the container and from the bean itself, when we look it up manually - only the injection does not work, heaven knows why... Any other injections work flawless, eg. SessionContext via @Resource and even other EJBs via @EJB, both by jndi-name and by type. It's only the queue, that refuses to be injected...

                • 5. Re: NameNotBound for injected Queue
                  dornus Novice

                  It never worked for me either. I just ended up doing this

                   @Resource(name = "ConnectionFactory")
                   QueueConnectionFactory factory;
                  
                   //@Resource (name="queue/myQueue")//todo doesn't work..must do manually below
                   //Queue queue;
                  
                  public void someMethod(){
                   QueueConnection cnn = null;
                   QueueSession sess = null;
                   QueueSender sender = null;
                  
                   try {
                   final InitialContext ctx = new InitialContext();
                   final Queue queue = (Queue) ctx.lookup("queue/myQueue");
                   //final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
                   cnn = factory.createQueueConnection();
                   sess = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
                  ...
                  }