1

我有一个添加 msmq 消息的 wcf 服务我还有一个 Windows 侦听器,它从私有队列中读取消息并处理消息。

protected override void OnStart(string[] args)
{
// initialises the queue and sets QueueAccessMode.Receive
MessageQueue queue...;

queue.ReceiveCompleted += ProcessEvent;
queue.BeginReceive();
}

public void ProcessEvent(Object source, ReceiveCompletedEventArgs asyncResult)
{
MessageQueue queue = (MessageQueue)source;
try
{

 Message msg = queue.EndReceive(asyncResult.AsyncResult);
 msg.Formatter = new XmlMessageFormatter(new[] { typeof(MyEvent) });

try

{
MyEvent e = (MyEvent) msg.Body;
Process(e);

}catch(exception e)

{
  HandleMessageFault(msg, queue);
 //  how can i put this message back in the queue or another queue at this point?
// will the msmq put it back in the queue automatically ?

}


}
catch()
{

// or how to handle here ?

}

}

我尝试将消息放回同一个队列,但它似乎不起作用但也没有错误

private void HandleMessageFault(Message message, MessageQueue currentQueue)
    {
        message.AppSpecific++;            

        using (TransactionScope scope = new      TransactionScope(TransactionScopeOption.Required))
        {
            currentQueue.Send(message);    
            scope.Complete();
        }


    }
4

0 回答 0