Unsubscribing Dynamic Durable Subscribers
There may be cases where you want to explicitly unsubscribe a
durable subscriber in a client application. To remove a dynamic durable
subscription, you can invoke the Session.unsubscribe method:
...
private void exit() {
try {
subscriber.close();
tSession.unsubscribe("BorrowerA");
tConnect.close();
} catch (javax.jms.JMSException jmse){
jmse.printStackTrace();
}
System.exit(0);
}
...For nondurable subscriptions, calling the close() method on the TopicSubscriber class is sufficient. For
durable subscriptions, there is an unsubscribe(String name) method on the
TopicSession object, which takes the
subscription name as its parameter. This informs the JMS provider that
it should no longer store messages on behalf of this client. You cannot
call the unsubscribe() method without
first closing the subscription (you will get an exception if you do
this). Hence, both methods need to be called for durable
subscriptions.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access