Results 1 to 9 of 9

Thread: How to unsubscribe a Durable Subscription using Spring DMLC

  1. #1
    Join Date
    Jul 2012
    Posts
    6

    Question How to unsubscribe a Durable Subscription using Spring DMLC

    Hi,
    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 !!

    Thanks,
    Gourab

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Jul 2012
    Posts
    6

    Default

    Hi I tried as you suggested but getting the following exception


    SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
    Throwable occurred: com.ibm.msg.client.jms.DetailedInvalidClientIDExce 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..");


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

    });

    }

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    You can set the clientId on the connection factory.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Jul 2012
    Posts
    6

    Default

    Quote 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 at 01:25 PM.

  6. #6
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    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(...).
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  7. #7
    Join Date
    Jun 2012
    Posts
    5

    Default 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. #8
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  9. #9
    Join Date
    Jun 2012
    Posts
    5

    Default It worked!!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •