How can I remove messages from a queue?

前端 未结 4 1272
-上瘾入骨i
-上瘾入骨i 2021-01-05 05:11

I have messages that get stuck in queue and I am looking for a way to programmatically remove them.

Is there a way to remove messages from a queue if it has been sit

4条回答
  •  执念已碎
    2021-01-05 05:51

    I think you can do something like this:

    MessageQueue queue = new MessageQueue(@".\private$\SomeTestName");
    var messages = queue.GetAllMessages();
    var messagesToDelete = messages.Where(m => m.ArrivedTime < DateTime.Now.AddDays(-1)).ToList();
    messagesToDelete.ForEach(m=>queue.ReceiveById(m.Id));
    

    Obviously, you'll have to modify the date stuff to correspond with your scenario.

提交回复
热议问题