6 Replies Latest reply on Sep 4, 2011 10:51 AM by ekfliu

    How to make Durable Subscribers to work?

    yairogen

      I have the following snippet:

       

       

      <bean id="messageListener2" class="com.messaging.test.ExampleListener2" />

       

      <bean id="destination" class="org.hornetq.jms.client.HornetQTopic">
        <constructor-arg name="name" value="test" />
      </bean>

       

      <bean id="jmsContainerTwo"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="destination" ref="destination" />
        <property name="messageListener" ref="messageListener2" />
        <property name="durableSubscriptionName" value="two" />
        <property name="messageSelector" value="myHeader='123'" />
      </bean>

       

       

      This works fine, but when I add the following in "jmsContainerTwo":

       

      <property name="subscriptionDurable" value="true" />

       

      The messages I send to reach the client.

       

      I've created the topic via the JMX API. Haven't found a way of defining the topic is durable fron the HornetQ server perspective - only from the client as stated above.

       

      Does anyone have an idea what might go wrong?

       

      Thanks,

       

      Yair

       

        • 1. Re: How to make Durable Subscribers to work?
          clebert.suconic

          I don't know much about spring...

           

          But this doesn't make anything:

           

           

          <bean id="destination" class="org.hornetq.jms.client.HornetQTopic">
            <constructor-arg name="name" value="test" />
          </bean>

           

           

          It just creates an Object of hornetQTopic, but it doesn't actualy create a phisical topic. You should either use createTopic on server controls methods or use the configuration.

          • 2. Re: How to make Durable Subscribers to work?
            yairogen

            I know this only creates a Topic object. this is what I need. I created the real topic using the hornetq config file. However, I fear that the topic is not persistent hence does not support durablity.

             

            Any ideas?

             

            Yair

            • 3. Re: How to make Durable Subscribers to work?
              clebert.suconic

              All you need is to make sure you use Persistence, and the Journal. And that you create your subscriptions (or queues) as durable.

              • 4. Re: How to make Durable Subscribers to work?
                ekfliu

                Believe it or not <property name="subscriptionDurable" value="true" /> does absolutely nothing in DefaultMessageListenerContainer.

                 

                First make sure jms is configured to give permission to allow durable subscription to be created.

                 

                   <security-settings>

                      <security-setting match="#">

                         <permission type="createNonDurableQueue" roles="guest"/>

                         <permission type="deleteNonDurableQueue" roles="guest"/>

                         <permission type="createDurableQueue" roles="guest"/>

                         <permission type="deleteDurableQueue" roles="guest"/>

                         <permission type="consume" roles="guest"/>

                         <permission type="send" roles="guest"/>

                      </security-setting>

                   </security-settings>

                 

                    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

                                    <property name="jndiName" value="java:comp/env/jms/ConnectionFactory" />

                    </bean>

                 

                  <bean id="durableConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">

                    <property name="targetConnectionFactory" ref="connectionFactory"/>

                    <property name="clientId" ref="hostIpAddress" />

                          </bean>

                 

                  this client id here must be unique for each subscriber, i use server ip address, assuming one subscriber per server.

                 

                <bean id="topicListenContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

                                    <property name="connectionFactory" ref="durableConnectionFactory"/>

                                    <property name="destination" ref="someTopic"/>

                                    <property name="pubSubDomain" value="true" />

                                    <property name="subscriptionDurable" value="true" />

                                    <property name="durableSubscriptionName" value="SomeTopicSubscription" />

                                    <property name="messageListener" ref="jmsTopicMessageHandler" />

                                    <property name="concurrentConsumers" value="1" />

                                    <property name="taskExecutor" ref="staticPoolExecutor" />

                                    <property name="sessionAcknowledgeMode">

                                              <util:constant static-field="javax.jms.Session.AUTO_ACKNOWLEDGE"/>

                                    </property>

                          </bean>

                 

                this should work, oh yeah subscriptionDurable here just use by listener container to do configuration validation check. So if you have say concurrentConsumers greater than one with subscriptionDurable set to true it will throw exception on startup.

                 

                Also the connection factory here cannot be picked up by java:/JmsXA that can be used for sending and listen by MDB but cannot be used by DefaultMessageListenerContainer for reading, use java:/XAConnectionFactory.

                • 5. Re: How to make Durable Subscribers to work?
                  yairogen

                  Thanks Frank for your great answer. one small things that puzzles me. Why do we need both the clientId and the "durableSubscriptionName"?

                  • 6. Re: How to make Durable Subscribers to work?
                    ekfliu

                    I believe the client id is tied to the connection, and each connection can have multiple durable subscribers. So it is more like a combination of clientId/Subscription name that uniquely identified by the server.