开发者

How can I programatically purge an ActiveMQ queue using the Apache.NMS API?

开发者 https://www.devze.com 2023-02-11 04:15 出处:网络
I need the ability to purge a queue pro开发者_C百科gramatically using Apache.NMS (C#). I\'ve been looking through the NMS API, but see no such capability. Does it exist?There isn\'t a direct way to fl

I need the ability to purge a queue pro开发者_C百科gramatically using Apache.NMS (C#). I've been looking through the NMS API, but see no such capability. Does it exist?


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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消