Announcement Announcement Module
No announcement yet.
How to unsubscribe a Durable Subscription using Spring DMLC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to unsubscribe a Durable Subscription using Spring DMLC

    Can any one help me to find out a way how to unsubscribe a durable subscription using spring DefaultMessageListenerContainer.

    In plain JMS we just need to do is -> session.unsubscribe("name of the durable subscription")

    I did not get any method in DefaultMessageListenerContainer.

    Appreciate your suggestion !!


  • #2
    You can just stop() the container. If you mean to permanently unsubscribe, there's no support for that in the DMLC, you'd have to use JmsTemplate.execute() to do that (with a SessionCallback), after stopping the container.


    • #3
      Hi I tried as you suggested but getting the following exception

      SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
      Throwable occurred: ption: JMSCC0101: The client ID cannot be null. Specify a non-null client ID.

      My code snippet

      JmsTemplate template = new JmsTemplate(defaultJmsMsgListenerContainer.getConn ectionFactory());

      template.execute(new SessionCallback() {

      public Object doInJms(Session session)
      throws JMSException {
      // TODO Auto-generated method stub
      System.out.println("Going to unsubscribe..");

      System.out.println("unsubscribe success..");
      return null;




      • #4
        You can set the clientId on the connection factory.


        • #5
          Originally posted by Gary Russell View Post
          You can set the clientId on the connection factory.
          Thanks Gary !!

          My Issue is I am using DMLC and you are suggesting to use JMSTemplate. Can I mix both DMLC and JMSTemplate ???

          What I mean by that is :

          DMLC will be configured to listen to messages/message listener and JMSTemplate will be used to unsubscribe..

          I was not able to figure out how to use both in my requirement.
          Last edited by gourabp; Jul 10th, 2012, 01:25 PM.


          • #6
            Just inject the same connection factory (with the clientId set) into both the DMLC and a JmsTemplate instance. The clientId will be assigned to the connection(s) created by the factory (a single connection if you use the CachingConnectionFactory).

            In your code where you want to control the subscription, inject the DMLC and JmsTemplate into your code (e.g. @Autowired). When you want to unsubscribe, execute dmlc.stop(), followed by jmsTemplate.execute(...).


            • #7
              client id and name already in use

              hey gaurob and gary,,

              i tried the above workaround of using the jmstemplate to unsubscribe , it gives me a client id already in use exception..have u faced it before

              please help


              • #8
                If you are using a CachingConnectionFactory, try setting cacheConsumers to false.

                Or, if you need consumer caching, call resetConnection() on the factory after you have unsubscribed. That will close the connection and clear the cached sessions.


                • #9
                  It worked!!

                  thanks a ton Gary, that is wat i was missing that i was using a cachedconnectionfactory.