2011-07-28 421 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