我正在使用.net框架来处理ws队列。是否可以从队列中删除/删除消息?
答案 0 :(得分:0)
检索它会将其从队列中删除。如果您不想对其执行任何操作,则可以丢弃检索到的消息。
// Hit up MSMQ for list of new messages
var queuedMessages = myMessageQueue.GetAllMessages();
// Receive actual message to remove from the message queue
var messages = new List<Message>();
foreach (var queuedMessage in queuedMessages)
{
// Receive the message, which removes it from the queue.
try
{
messages.Add(this.messageQueue.ReceiveById(queuedMessage.Id));
}
// If it's already been removed, we skip over it.
// TODO: Should try to catch only the "removed" exception
catch (Exception)
{
continue;
}
}
返回消息;