簡體   English   中英

對於帶有MSMQ 3.0綁定的單向WCF服務:ServiceHost.Faulted事件處理的正確行為是什么?

[英]For one-way WCF service with MSMQ 3.0 binding: What is correct behavior for ServiceHost.Faulted event handling?

方案1 :在發生故障的事件中,我正在重新啟動服務,這意味着重新創建ServiceHost。

我已經實現了IErrorHandler來處理有毒消息,並且在將有毒消息移動到有毒隊列之后,它調用RestartService方法。

現在,當消息中毒時,將首先調用Faulted事件,該事件將調用RestartService,但在成功成功打開ServiceHost之后不久,它將再次出現Faulted,但在這里,我已停止進一步重新啟動它。

在這段時間內,在單獨的線程上兩次調用了IErrorHandler.HandleError,並且在兩次調用IErrorHandler.HandleError的末尾(如果異常是MsmqPoisonMessageException的情況下)兩次都無法找到將消息移至中毒隊列的消息,而第二次將消息移至中毒隊列的消息它將重新啟動服務。

以下是被調用的方法序列:

ProcessMessage – message throws exception every time e.g. DB server is down
    ServiceHost.Faulted 
        RestartService
            ServiceHost.Faulted
                RestartService – skipped as still first call to RestartService not finished
    IErrorHandler.HandleError - Message not found to move to poison queue
        RestartService
    IErrorHandler.HandleError - Message moved to poison queue
        RestartService – skipped as a call to RestartService by first call to IErrorHandler.HandleError is not yet finished

方案2:在發生故障的事件中,我重新啟動服務。

以下是被調用的方法序列:

ProcessMessage – message throws exception every time e.g. DB server is down
    ServiceHost.Faulted
    IErrorHandler.HandleError - Message moved to poison queue
        RestartService 

現在,我擔心的是,如果我遵循方案2,該方案更干凈,性能更好,但是如果服務由於MsmqPoisonMessageException服務以外的其他原因而出現故障,則該服務將停止響應。

在這種情況下,您建議什么解決方案?

我在Windows XP和Windows Server 2003上使用MSMQ 3.0。

對於MSMQ 3,我們看到在FaultHandler中重新啟動服務不是一個好主意,因為它可能導致消息重新處理,然后才能將消息移至中毒隊列。

如果服務在處理有毒消息之前重新啟動(這將會發生,因為它會發生故障->在引發poisonMessageException之前引發有故障的事件),則新服務主機可能會開始處理該消息,然后中毒處理無法找到中毒的消息。

我看到的問題是:如果WCF服務出現異常和故障怎么辦?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM