7 Replies Latest reply on May 22, 2014 12:40 AM by Roman Ju

    Somp client to publish and subscribe queues in HornetQ

    Vijay Mudunuri Newbie

      Hi,

       

      I am using Apache ActiveMQ stomp client (C#) to publish and subsribe queues in HornetQ. I installed the latest version 2.2.14 final. I followed the user documentation and edited some of the configuration files (hornetq-configuration.xml, hornetq-jms.xml) to add the stomp acceptor, and queues. In the hornetq-jms.xml file I created a queue.

       

      <queue name="test">

          <entry name="/queue/test"/>

      </queue>

       

      In the application when I created a publisher by creating destination, it worked with out any problems. It is also publish the data. But when I created a consumer with the same destination name (or queue name), hornetq is throwing an exception HornetQException[errorCode=100 message=Queue /queue/test does not exist]. I googled around and tried some solutions but they didn't work for me. How could I make the consumer work.

       

      Thanks & Regards,

      Vijay.

        • 1. Re: Somp client to publish and subscribe queues in HornetQ
          Yong Hao Gao Master

          Can you give the piece of your code for publishing and receiving ?

           

          Howard

          • 2. Re: Somp client to publish and subscribe queues in HornetQ
            Vijay Mudunuri Newbie

            Hi Howard,

             

            Here is the code that I am using.

             

            // For publishing a text message

            ConnectionFactory cf = new ConnectionFactory("tcp://localhost:61613");

            IConnection connection = cf.CreateConnection();

            ISession session = connection.CreateSession();

            IDestination destination = session.GetDestination("test");

            connection.Start();               

            IMessageProducer producer = session.CreateProducer(destination);               

            producer.DeliveryMode = MsgDeliveryMode.Persistent;

            ITextMessage messg = session.CreateTextMessage("Some Text");

            producer.Send(messg);

             

            // For receiving the message published by publisher

            ConnectionFactory cf = new ConnectionFactory("tcp://localhost:61613");

            IConnection connection = cf.CreateConnection();       

            ISession session = connection.CreateSession();

            IDestination destination = session.GetDestination("test");

            connection.Start();

            IMessageConsumer consumer = session.CreateConsumer(destination); // Exception thown at this line

             

            At the point when I create a consumer the hornetq is throwing an exception

            • 3. Re: Somp client to publish and subscribe queues in HornetQ
              Yong Hao Gao Master

              Thanks. I don't how the client translates the destination name into Stomp frame headers. I had run some example long before and the syntax for getting a destination is something like

               

              session.GetDestination("queue://test");

               

              Not sure if it still works. Anyway you can get a tcp monitor tool to make sure the destination 'test' is translated into 'jms.queue.test' down in the Stomp layer.

               

              Howard

              • 4. Re: Somp client to publish and subscribe queues in HornetQ
                Vijay Mudunuri Newbie

                Hai Howard,

                 

                I am using the syntax provided by the C# stomp client. But I also changed the syntax and tried it but it always raises this exception. I tried to use the stomp client for java and it worked without any problem, may be there is a problem with the stomp client in c#. Any way I reported this problem to my boss. We may think of changing HornetQ to ActiveMQ. Thanks for your response.

                 

                Thanks and Regards,

                vijay.

                • 5. Re: Somp client to publish and subscribe queues in HornetQ
                  Michael Justin Novice

                  Your code

                     IDestination destination = session.GetDestination("test");

                  seems not to specify wether it is a Topic or Queue destination.

                   

                  The examples for the ActiveMQ NMS C# client on http://activemq.apache.org/nms/examples.html are:


                               // Hard coded destinations:
                               //    IDestination destination = session.GetQueue("FOO.BAR");
                               //    Debug.Assert(destination is IQueue);
                               //    IDestination destination = session.GetTopic("FOO.BAR");
                               //    Debug.Assert(destination is ITopic);
                               //
                               // Embedded destination type in the name:
                               //    IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
                               //    Debug.Assert(destination is IQueue);
                               //    IDestination destination = SessionUtil.GetDestination(session, "topic://FOO.BAR");
                               //    Debug.Assert(destination is ITopic);
                               //
                               // Defaults to queue if type is not specified:
                               //    IDestination destination = SessionUtil.GetDestination(session, "FOO.BAR");
                               //    Debug.Assert(destination is IQueue);
                               //
                               // .NET 3.5 Supports Extension methods for a simplified syntax:
                               //    IDestination destination = session.GetDestination("queue://FOO.BAR");
                               //    Debug.Assert(destination is IQueue);
                               //    IDestination destination = session.GetDestination("topic://FOO.BAR");
                               //    Debug.Assert(destination is ITopic);

                   

                  Did you try these?

                  • 6. Re: Somp client to publish and subscribe queues in HornetQ
                    Vijay Mudunuri Newbie

                    Hai Michael,

                     

                    Actually it was not the problem with the declaration of topic or a queue in my program. HornetQ doesnot support the declaration of a topic or queue in the form "destination:/queue/ExampleQueue". This was reported in the post https://community.jboss.org/message/594176. However, there is a work around provided in this post. The apache nms library in .net has to be slightly modified to declare queues and topics as"jms.queue.ExampleQueue" instead of "/queue/ExampleQueue". I followed these instructions and finally made it worked. Thanks for your reply.

                     

                    Regards,

                    Vijay.

                    • 7. Re: Somp client to publish and subscribe queues in HornetQ
                      Roman Ju Newbie

                      Here's a small tutorial for C#  that I created in case anyone is interested:

                      http://completelycold.com/?p=80