11 Replies Latest reply on Nov 20, 2009 1:12 PM by Jeff Mesnil

    Embedded HornetQ and Topics

    Levi Baker Newbie

      I'm having trouble setting up topics using embedded HornetQ.

      I keep getting a InvalidDestinationException when I try to create a subscriber for a topic.

      I've scoured the documentation, but haven't found anything that helps. I may just be looking in the wrong places. From what I can tell when I create my topics, connections and sessions; my topics are being deployed. So when I try to create a subscriber I get an invalid destinations exception.

      Any ideas?

        • 1. Re: Embedded HornetQ and Topics
          Clebert Suconic Master

          Do you have some code showing what you're trying to achieve?

          • 2. Re: Embedded HornetQ and Topics
            Levi Baker Newbie

            Basicaly what I am trying to do is upgrade some existing code that used JMS and a JBoss server to use embedded HornetQ instead.

            I get the exception at the session.createSubscriber line.

            public void setTopicSubscriber(String topicName, MessageListener subscriber, String selector, boolean noLocal) {
             topicName = topicPrefix + topicName;
             //topicName = topicPrefixName + topicName;
             try {
             HornetQSession session = sessions.get(topicName);
             Topic topic = (HornetQTopic) destinations.get(topicName);
             * Create a subscriber to the topic, using the message selector. The third parameter is set to true which inhibits the delivery of messages published by its own connection
             TopicSubscriber topicSubscriber = session.createSubscriber(topic, selector, noLocal);
             TopicConnection topicConnection = (TopicConnection) connections.get(topicName);
             } catch (javax.jms.InvalidDestinationException e){
             } catch (javax.jms.JMSException e) {
             } catch (Exception e) {

            The following is the highlights of setting up the topics and queues.
            connectionFactory = new HornetQConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()));
            connection = (HornetQConnection) connectionFactory.createConnection();
            session = (HornetQSession) connection.createSession(transacted, ackMode);
            if (destinationName.contains("topic")) {
             destination = (HornetQDestination) new HornetQTopic(env.get(destinationName));
            } else if (destinationName.contains("queue")) {
             destination = (HornetQDestination) new HornetQQueue(env.get(destinationName));
            producer = (HornetQMessageProducer) session.createProducer(destination);
            connections.put(destinationName, connection);
            destinations.put(destinationName, destination);

            Where connections, destinations, messageProducers and sessions are hashtables.

            • 3. Re: Embedded HornetQ and Topics
              Jeff Mesnil Master

              how do you configure your topics?
              have you looked at the example jms/topic?

              • 4. Re: Embedded HornetQ and Topics
                Levi Baker Newbie

                I have looked at most of the examples. I'm trying to embed it so I've been following example jms/embedded. I'm not having trouble with queues, just topics.

                What do you mean how am I configuring my topics?

                I'm directly instantiating them.

                destination = (HornetQDestination) new HornetQTopic(topicName);

                • 5. Re: Embedded HornetQ and Topics
                  Andy Taylor Master

                  The code you are showing is just client code. You need to configure/create the destinations on the server. There are a few ways to do this, either via the configuration file or programatically via a JMSServermanager Object. take a look at the EmbeddedExample.

                  • 6. Re: Embedded HornetQ and Topics
                    Levi Baker Newbie

                    Do you mean step 4 of the Embedded Example?

                    That uses the Core API, I'm trying to use the JMS API.
                    Also I don't see any JMSServerManager objects in the Embedded Example to take a look at. The Core API works fine for queues, but I can't find any support for topics.

                    Are they any examples of how to correctly use a JMSServerManager object?

                    • 7. Re: Embedded HornetQ and Topics
                      Andy Taylor Master

                      take a look at step 8.

                      // Step 8. Start the JMS Server using the HornetQ core server and the JMS configuration
                       JMSServerManager jmsServer = new JMSServerManagerImpl(hornetqServer, jmsConfig);

                      and then

                       jmsServer.createTopic("myTopic", "topic/myTopic");

                      In the core API there is no concept of queue thats why you cant find anything. Read the section in the manual about addresses and queues to see how topics work.

                      • 8. Re: Embedded HornetQ and Topics
                        Levi Baker Newbie

                        Okay, I'm getting you now. I see why I couldn't find what I was looking for.

                        I can't find the EmbededExample you are talking about. Is it the one in the file path: examples\jms\embedded?

                        Step 8 of the copy I have is:

                        // Step 8. Receive the message.
                         TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);
                         System.out.println("Received TextMessage:" + messageReceived.getText());

                        • 10. Re: Embedded HornetQ and Topics
                          Levi Baker Newbie

                          Ataylor, Thanks for all your help. That example helps a bunch.

                          But I've got a new problem. The HornetQ libraries I have are deficient. The hornetq-jms.jar I have doesn't have the path for the imports:

                          import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
                          import org.hornetq.jms.server.config.JMSConfiguration;
                          import org.hornetq.jms.server.config.QueueConfiguration;
                          import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
                          import org.hornetq.jms.server.config.impl.JMSConfigurationImpl;
                          import org.hornetq.jms.server.config.impl.QueueConfigurationImpl;

                          Under server these isn't a config folder. Is there some where I can get this library.

                          • 11. Re: Embedded HornetQ and Topics
                            Jeff Mesnil Master


                            "levidean" wrote:

                            Under server these isn't a config folder. Is there some where I can get this library.

                            from the trunk.

                            But you don't need these classes.

                            If you are using HornetQ 2.0.0.Beta5, create a JMSServerManagerImpl and use the createTopic() method to create and deploy the JMS topic on the server