1

I need to remove/delete my topic subscriber. I found this http://activemq.apache.org/manage-durable-subscribers.html
However, it's not good enough for us. We want to control the timing of removing a subscriber, and no matter there are any message or not. Besides, our program is written by C#. So the best solution for us is NMS API.

Thanks.


Here are the code,

Apache.NMS.ActiveMQ.ConnectionFactory factory = new Apache.NMS.ActiveMQ.ConnectionFactory(m_brokerURI);
m_connection = factory.CreateConnection(username, password);

Apache.NMS.ActiveMQ.Connection con = (Apache.NMS.ActiveMQ.Connection)m_connection;
ISession session = m_connection.CreateSession(AcknowledgementMode.AutoAcknowledge);

try
{
    session.DeleteDurableConsumer(strQueueName);
}
catch (Exception ex)
{
    // log the error message
}

Update

Our scenario is quite simple.

  1. A client built a queue and subscribed a consumer on a topic.
  2. the client side closed the connection.
  3. delete the consumer on the server side(as the example code in the last update)

Here is the snapshot of activemq broker via jconsole: jconsole snapshot

We would like to remove the subscriber “7B0FD84D-6A2A-4921-967F-92B215E22751” by following method, But always got this error "javax.jms.InvalidDestinationException : No durable subscription exists for: 7B0FD84D-6A2A-4921-967F-92B215E22751"

strSubscriberName = “7B0FD84D-6A2A-4921-967F-92B215E22751”
session.DeleteDurableConsumer(strSubscriberName);
Kimi Wu
  • 309
  • 1
  • 4
  • 17

1 Answers1

1

To delete a durable subscription from the NMS API you use the DeleteDurableConsumer method defined in ISession. You must call this method from a Connection that uses the same client Id as was used when the subscription was created and you pass the name of the subscription that is to be removed. The method will fail if there is an active subscriber though so be prepared for that exception.

In the sample code you don't set a Client Id on the connection. When working with durable subscriptions you must, must, MUST always use the same client Id and subscription name. So in you same you will get this error until you set the client Id to the same value as the connection that created the subscription in the first place.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • We always got such error:"javax.jms.InvalidDestinationException : No durable subscription exists for: 31E8E994-7276-4E4A-8F18-EA507448535E". We use a GUID as the subscriber name and We copied the name from JConsole. So it shouldn't be a typo issue. We also offline the client so it should be inactive subscriber as you mentioned. Do we miss anything? – Kimi Wu Apr 23 '13 at 06:12
  • 1
    My magic eight ball says, all signs point to show me the code. – Tim Bish Apr 23 '13 at 10:17
  • That small snippet doesn't really tell me anything. You should either post a complete test case or create a unit test that demonstrates the problem and create a Jira issue. The error indicates you have a consumer left on that subscription so ensure you called consumer.close() first. – Tim Bish Apr 24 '13 at 10:47
  • It works! We didn't know the Clinet Id is needed before. Thanks. – Kimi Wu Apr 29 '13 at 09:04