5 Replies Latest reply on Feb 28, 2012 8:17 AM by Clebert Suconic

    Created a queue, but it "does not exist"

    Tom Anderson Newbie



      This is an incredibly elementary question. Sorry.


      I have a HornetQ 2.2.5.Final server running in standalone mode. So far so good. I have modified my installation to grant the createDurableQueue permission to the guest role (just for testing!), but otherwise, it is exactly as it was when i unzipped the download.


      I would like to write a Java program, just a simple standalone command-line program, which can connect to the server, and do one (or more) of three things: create a new JMS queue, send a text message to an existing JMS queue, and receive a text message from an existing JMS queue.


      I actually want to do much more than this, but this would be a great start!


      I've looked at some of the example code, and read quite a bit of the user guide, and this is what i've got:




      I can run the create and send operations without apparent error (no exceptions in the client, no messages in the server logs). However, if i try to receive a message that i have previously sent, i get an exception saying "Queue jms.queue.MyQueue does not exist". Here's the exact conversation i have with my program (via a shell script autogenerated by Gradle, which i don't believe is doing anything exciting):


      $ build/install/HornetQDemo/bin/hq localhost 5445 MyQueue create jms.queue.MyQueue

      $ build/install/HornetQDemo/bin/hq localhost 5445 MyQueue send "hello world"

      $ build/install/HornetQDemo/bin/hq localhost 5445 MyQueue receive

      Exception in thread "main" javax.jms.InvalidDestinationException: Queue jms.queue.MyQueue does not exist

          at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:286)

          at org.hornetq.core.client.impl.ClientSessionImpl.internalCreateConsumer(ClientSessionImpl.java:1685)

          at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:461)

          at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:427)

          at org.hornetq.core.client.impl.DelegatingSession.createConsumer(DelegatingSession.java:188)

          at org.hornetq.jms.client.HornetQSession.createConsumer(HornetQSession.java:537)

          at org.hornetq.jms.client.HornetQSession.createConsumer(HornetQSession.java:383)

          at org.hornetq.jms.client.HornetQSession.createConsumer(HornetQSession.java:353)

          at org.hornetq.jms.client.HornetQSession.createReceiver(HornetQSession.java:823)

          at HornetQDemoApp.receive(HornetQDemoApp.java:70)

          at HornetQDemoApp.main(HornetQDemoApp.java:39)

      Caused by: HornetQException[errorCode=100 message=Queue jms.queue.MyQueue does not exist]

          ... 11 more


      I assume that i am not creating the queue properly. What do i need to do to create a queue?





      EDIT: I tried the example client code at http://anonsvn.jboss.org/repos/hornetq/trunk/examples/jms/instantiate-connection-factory/src/org/hornetq/jms/example/InstantiateConnectionFactoryExample.java and i get exactly the same error (sending succeeds, receiving fails). That code only accesses the queue, it doesn't create it, so this suggests the problem is the way i create queues, not the way i use them.


      If i look at the files $HORNET_HOME/data/bindings/hornetq-bindings-1.bindings, then i can see strings containing the names and addresses of the queues i have created. After running the create command, i can do:


      $ strings -e l ./bindings/hornetq-bindings-1.bindings








      Similarly, after running the send command, i can see the message in $HORNET_HOME/data/journal/hornetq-data-1.hq:


      $ strings -e l ./journal/hornetq-data-1.hq

      hello world


      Can anyone suggest what might be going on? I can feel my sanity slipping away ...


      SON OF EDIT: Oh, okay, fixed it.


      What i failed to appreciate is that when creating a JMS queue using the core API, the name of the queue needs to have the jms.queue. prefix. So the name and address in my case should both be jms.queue.MyQueue. If i create the queue that way, everything works.


      I am still puzzled as to how the message send worked when i was creating the queue wrongly, since i was sending to a nonexistent queue. Now, if don't run the create before the send, it blows up, so it seems the queue does need to be created before it can be sent to. But if i create the queue wrongly, that's good enough for sending, but not for receiving. What's going on there?

        • 1. Re: Created a queue, but it "does not exist"
          Clebert Suconic Master

          HornetQClient.createQueue doesn't create the queue at the server.


          You're using the core-api. When you send to an unexistent address it's the same as sending to an unbound topic.

          • 2. Re: Created a queue, but it "does not exist"
            Tom Anderson Newbie

            As you can see, i'm using ClientSession.createQueue to create the queue, and that does indeed create the queue on the server.


            You say "when you send to an unexistent address it's the same as sending to an unbound topic". Okay. So what happens when you send to an unbound topic?


            The thing that strikes me as odd is that if i send (using JMS) to a nonexistent queue, then i get an exception. But if i create a queue with the wrong name (MyQueue rather than jms.queue.MyQueue), then i don't get an exception, i can send the message fine. But i can never receive it, because when i try, i get an exception! It looks to me like the behaviour of sending and receiving messages is inconsistent. Have i misunderstood this?

            • 3. Re: Created a queue, but it "does not exist"
              Clebert Suconic Master

              Sending messages to an unbound topic in JMS means.. the message will go nowhere.


              On the HOrnetQ case you can define a DLQ where messages will be address if not-routed to any queues. But that's a HornetQ specific feature.



              on your test you are using createQueue, without using the jms.queue definition.


              session.createQueue(qualifiedQueueName, qualifiedQueueName, true);



              And when you're creating the consumer you are using JMS, what will need a JMS Queue. a JMS Queue is translated into HOrnetQ's core queue with a jms.queue. prefix.


              You should use JMS Objects to create the JMS Queue IMO. (or use core to also read the message).

              • 4. Re: Created a queue, but it "does not exist"
                Tom Anderson Newbie

                Is it possible to create a queue using JMS objects? I thought it was only possible to connect to an existing queue. If it's possible to actually create a queue, then yes, i should definitely being doing that rather than using core objects.


                There is still some unexplained behaviour of sending messages to nonexistent queues: if i send a message to a JMS queue called MyQueue, then that should go to a core queue called jms.queue.MyQueue, yes? What i found was that if there was no queue called jms.queue.MyQueue, but there was one called MyQueue, then sending was still successful. But i could not receive the message.


                Thanks for your answers, Clebert.

                • 5. Re: Created a queue, but it "does not exist"
                  Clebert Suconic Master

                  First, you send to address.. you never send to a queue.


                  if you created an Address/Queue called MyQueue/MyQueue, you should consume from MyQueue.



                  On this case you are trying to consume from jms.queue.MyQueue, which is a different core-queue. (you used JMS wrapper on the consumer).



                  There are examples on the manual on how to create a jms queue. You should at least use the jms.queue prefix there.