4 Replies Latest reply on Jun 22, 2009 10:47 AM by Subendu Dasgupta

    JMS Topic and durable subscriber help

    Subendu Dasgupta Newbie

      My flow is

       

      File-Poller --> Bean (Do some validations on the file and send the results to camel) -> Camel --> JMS provider (put the message into a topic)

       

      The JMS provider config is below

       

      <jms:provider service="orderservice:orsjmsprovider"

                        endpoint="orsProvider"

                        destinationName="topic/ORS/Order"

                        replyDestinationName="topic/ORS/Order"

                        connectionFactory="#connectionFactory"

                            pubSubDomain="true"

                        />

       

      I also have a JMS consumer with target service as JMS producer as shown below

       

      <jms:consumer service="orderservice:orsjmsconsumer"

                        endpoint="jms"

                        targetService="orderservice:orsjmsprovider"

                        targetEndpoint="orsProvider"

                        destinationName="topic/ORS/Order"

                        durableSubscriptionName="FirstConsumer"

                        clientId="LOE-ORS-SubscriberId"

                        subscriptionDurable="true"                 

                        connectionFactory="#connectionFactory" />

       

      I am trying to write a client code to get the message which gets published on the topic, here is the sample code

       

                     Properties props = new Properties();

                     props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");

                     props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");

                     ctx = new InitialContext(props);

            

                   javax.jms.TopicConnectionFactory factory = (javax.jms.TopicConnectionFactory)ctx.lookup("TopicConnectionFactory");

                   javax.jms.TopicConnection conn = factory.createTopicConnection();

                   javax.jms.Topic mytopic = (javax.jms.Topic)ctx.lookup("topic/ORS/Order");

                   javax.jms.TopicSession session = conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);

                   topicSubscriber = session.createDurableSubscriber(mytopic, clientId);

                   topicSubscriber.setMessageListener(this);

       

      But i get,

       

      javax.naming.NameNotFoundException: topic/ORS/Order

           at org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:225)

           at javax.naming.InitialContext.lookup(InitialContext.java:392)

       

      What is missing in my configuration?

        • 1. Re: JMS Topic and durable subscriber help
          Torsten Mielke Apprentice

          Queues that are dynamically created at runtime do not get exposed in JNDI. So your lookup will fail and that is expected.

          In your Java code you can simply create the queue as needed, e.g.

           

          import org.apache.activemq.command.ActiveMQQueue;
          ...
          ActiveMQQueue queue = new ActiveMQQueue(queueName + "?consumer.exclusive=true");
          consumer = session.createConsumer(queue);
          

           

          You can also dynamically create queues using the JNDI  service:

           

          javax.jms.Topic mytopic = (javax.jms.Topic)ctx.lookup("dynamicTopics/topic/ORS/Order");
          

          See "Dynamically creating destinations" on http://activemq.apache.org/jndi-support.html

           

          Please note ActiveMQ does not provide a full JNDI service.

           

          Edited by: tmielke on Jun 22, 2009 10:47 AM

          • 2. Re: JMS Topic and durable subscriber help
            Subendu Dasgupta Newbie

            Hi,

             

            Thanks for the response.

             

            My requirement is to create a JMS Topic using the servicemix-jms component, and a application outside the ESB should subscribe to that Topic.

             

            So, is it not possible to subscribe to the topic created in ESB from an outside application? If yes, how?

            • 3. Re: JMS Topic and durable subscriber help
              Torsten Mielke Apprentice

              Sure, that's possible. If you know the topic name, simply use the code above. Just make sure your external JMS client and use ServiceMix components use the very same topic name.

              • 4. Re: JMS Topic and durable subscriber help
                Subendu Dasgupta Newbie

                I tried that, but I think the topic is not getting created. This is my flow

                 

                File Poller --> Camel --> Bean Su (Call Business logic) --> EIP static recipient --> JMS provider (creates a topic) --> file sender (writes the response)

                 

                I also have a durable JMS consumer listening to the topic.

                 

                The flow works fine, but I am not able to see the topic created in JConsole.

                 

                Note: If I run my client app, the topic gets created.

                 

                Here is again the configuration I am using

                 

                <jms:provider service="orderservice:orsjmsprovider"

                                  endpoint="orsProvider"

                                  destinationName="topic/ORS/Order"

                                  connectionFactory="#connectionFactory"

                                      pubSubDomain="true"

                                  />

                 

                <jms:consumer service="orderservice:orsjmsconsumer"

                                  endpoint="jmsconsumer"

                                  targetService="orderservice:orsjmsprovider"

                                  targetEndpoint="orsProvider"

                                  destinationName="topic/ORS/Order"

                                  durableSubscriptionName="FirstConsumer"

                                  clientId="LOE-ORS-SubscriberId"

                                  pubSubDomain="true" 

                                  subscriptionDurable="true"

                                  connectionFactory="#connectionFactory" />