4

WCF を使用していない場合、有害なメッセージをどのように処理しますか? 以下のコードはループを作成します。MSMQ が有害なメッセージを自動的に処理するシステムを提供しているかどうかに興味がありました。

MessageQueue mq = new MessageQueue(@".\Private$\My/Queue");

while (true)
{
    using (MessageQueueTransaction _transaction = 
            new MessageQueueTransaction())
    {
        _transaction.Begin();

        try
        {
            Message msg = mq.Receive(_transaction);

            //HandleMessage(msg);
            throw new Exception("Kaboom!");            

            _transaction.Commit();
        }
        catch (Exception ex)
        {
            _transaction.Abort();
        }

    }
}
4

1 に答える 1

4

I don't believe there is a simple way to handle poison messages using raw System.Messaging classes. I think the simplest solution is to set the "TimeToBeReceived" property on a message, but this is not perfect, because you may end up losing valid messages if the receiver is offline. I read somewhere that you can have real poison message handling in MSMQ using PInvoke, but was unable to find any resources on this.

I found this article with some ideas on how to manually handle poison messages. It might offer some ideas:

http://www.cogin.com/articles/SurvivingPoisonMessages.php

于 2009-04-10T22:19:40.037 に答える