I'm writing a Java JMS application that is responsible for comunication between cluster nodes. The messaging is done by publish\subscribe using Topic. The TopicSubscriber is created by calling TopicSession.createSubscriber(topic, null, true), meaning that it is not a durable subscriber. Now I'm implementing a "release" method that should unsubscribe the Subscriber (and then close the connection, etc). I saw that TopicSession.unsubscribe(String name) is relevant only for durable subscribers, so how do I unsubscribe a non-durable one? Is it necessary?
1
votes
1 Answers
2
votes
No, you don't need to issue TopicSession.unsubscribe()
for non-durable subscription. Closing the consumer will remove the subscription from JMS provider. You can also do Session.Close()
or Connection.Close()
to remove the subscription from JMS provider.
In your Release
method just close the subscriber or session or connection.
Unsubscribe is required only for durable subscriptions.