I need the ability to purge a queue programatically using Apache.NMS (C#). I've been looking through the NMS API, but see no such capability. Does it exist?
Asked
Active
Viewed 2,721 times
2 Answers
6
There isn't a direct way to flush a Queue from the NMS API, that's more of a management function. You can cast a IConnection instance into an Apahce.NMS.ActiveMQ.Connection and then call DeleteDestination. This would work if there were no consumers on the Queue but will throw an exception if there are.

Tim Bish
- 17,475
- 4
- 32
- 42
-
I wish NMS included a management API, but for now this accomplishes what I needed. Thanks for the tip, Tim! – Kilhoffer Feb 18 '11 at 17:10
-
Its not possible for NMS to include a management API as the broker is java based and managed via JMX. If you want to create an open source library to communicate with JMX via .NET then we can, but until then there's a limit to what can be done in NMS based clients. You could write some java based libraries to perform the management tasks you need and run them via IKVM in you .NET app I suppose. – Tim Bish Feb 25 '11 at 15:35
0
Not exactly sure what you mean by "flush" a queue (delete all messages?) but you can manage messages by setting the session transactional:
ISession consumerSession = = connection.CreateSession(AcknowledgementMode.Transactional);
Then you can use either:
//will remove message from queue on success
consumerSession.Commit();
or:
//on failure, back on queue
consumerSession.Rollback();

Perception
- 79,279
- 19
- 185
- 195

user1351848
- 127
- 1
- 1
- 9
-
1Delete all messages is what I meant. Transactions serve a different purpose. Tim Bish already answered my question. – Kilhoffer Apr 24 '12 at 21:56