2011-07-28 230 views

回答

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; 
     } 
    } 

返回消息;

+0

因此,从websphere队列中移除消息的唯一方法是简单地接收它? – macpak

+0

这不是* only *方法 - 您可以从runmqsc清除队列,即清除ql(system.default.local.queue),如果它不是持久的,则可以重新启动队列管理器,或者可以使用到期时间等等。但是WMQ和其他消息传递提供者的重点在于,如果没有定义的非持久性,到期等等,消息一直保存到应用程序收到它们。编辑:从上下文来看,消息提供者是什么有点不清楚,标题说WS MQ(= WebSphere MQ?),响应表示MSMQ和“WebSphere Queue”可能是WAS消息传递提供者。我在这里假设WMQ – strmqm