0 Replies Latest reply on Apr 14, 2005 2:36 PM by Praveen Vadlamudi

    using the same DurableSubscriber stored in jms_subscriptions

    Praveen Vadlamudi Newbie

      Hello. Hope that this question will be answered easily by some of you.
      I am trying to use a DurableSubscriber in my servlet so that the messages posted to the Topic while the subscriber is inactive can be received. This is what I do in init()

      resultTopic = (Topic)jndiContext.lookup(RESULT_JNDI_NAME));
      TopicConnectionFactory cf = (TopicConnectionFactory)jndiContext.
      lookup(CONNECTION_FACTORY));
      topicConn = cf.createTopicConnection();
      //m_topicConn.setClientID("ID:1");
      resultSession = topicConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      durSubscriber = resultSession.createDurableSubscribe (resultTopic, "MySubscriber");
      topicConn.start();

      And in the destroy() method I do:

      durSubscriber.close();
      topicConn.stop();
      resultSession.close();
      topicConn.close();

      The first time I run everything works fine, a subscriber is created and I get all the messages. If I see in the rms_subscriptions table I see
      "ID:1 MySubscriber ResultTopic" row.

      The problem is that if I stop and start my JBoss Server, instead of re-using the same subscription a new subscription is created and in the rms_subscriptions table I see 2 rows:
      "ID:1 MySubscriber ResultTopic"
      "ID:3 MySubscriber ResultTopic"

      As you can see the IDs are different. I am not sure how to reuse my previous DurableSubscription. I tried to setClientID to the topicConnection by doing:
      //m_topicConn.setClientID("ID:1"); and I get an exception:

      javax.servlet.ServletException: InitServlet.initJms(): javax.jms.InvalidClientIDException: This client id 'ID:1' is already registered!

      I did a little more digging and found this in the jbossmq-service.xml file:

      <!--
      | The ClientReconnectInterceptor is used to allow a client to connect to the server even
      | if it's clientID is allready being used by another client. This interceptor will disconnect
      | the previously connected client to allow the new connection to succeed. This is not enabled
      | by default since the JMS spec states that the 2nd client connecting to the server with the same
      | id should get an exception.
      -->
      <!--

      org.jboss.mq.server.ClientReconnectInterceptor
      <depends optional-attribute-name="NextInterceptor">jboss.mq:service=DestinationManager

      -->

      But I am not sure if this is the correct way to re-use the same DurableSubscriber. Needing directions on what to do.

      Thanks in advance for your help
      Praveen