2014-12-18 44 views
0

作爲我的original question的後續,當從我的Web服務拋出異常時,它們被ServiceStack轉換爲更友好的HTTP響應代碼,這對於感興趣的問題是有問題的一個Windows服務(MQ邏輯服務器),它只收到500個內部服務器錯誤。如何獲取RegisterHandler中的ServiceStack RabbitMQ消息,第2部分

有沒有辦法堅持的OutBoundAgentNotFoundException在內部異常屬性,這樣我可以在其他地方並採取行動關閉它檢查呢?

Web服務端點:

mqServer.RegisterHandler<OutboundILeadPhone>(m => 
{ 
    var db = container.Resolve<IFrontEndRepository>(); 
    db.SaveMessage(m as Message); 
    return ServiceController.ExecuteMessage(m); 
}, PhoneApi.OnExceptionLeadInformation , 1); 

窗口服務異常處理程序:

public static void OnExceptionLeadInformation(IMessage<OutboundILeadPhone> request, Exception exception) 
{ 

     // Here is where I'd like to inspect the type of exception and Nak/requeue the Message 

} 

窗口服務端點:

//This is a callback that the phone system uses to notify us of what routing decision was made. 
//It's now up to this method to assign it to the agent, or send it back to the queue via exceptions 
public object Get(OutBoundILeadRequest request) 
{ 
    if (request == null) throw new ArgumentNullException("request"); 

    _log.Debug("OutBoundILeadRequest: {0}".Fmt(request.ToJson())); 

    // assign the agent to the lead 

    // Agent phone extension is called, 1 and 2 are pressed, accepts call "Agent":"9339","Status":"0" 
    // Agent phone extension is called, 1 and 2 are pressed, but no answer or wrong number "Agent":"9339","Status":"0" 
    if (request.Status == "0" && !string.IsNullOrEmpty(request.Agent)) 
    { 
     //assignment 

    } 


    // throw will send it back to the queue and then it will be re-tried, then it will be sent to the dlq 
    // https://stackoverflow.com/questions/27519209 


    // Agent phone extension is called, but no response from Agent => "AgentsTalking":"0","Status":"3" 
    // this action puts them in NOT READY (Cisco Agent Desktop)    
    if (request.Status == "3" && !string.IsNullOrEmpty(request.AgentsTalking) && request.AgentsTalking == "0") 
    { 
     //retry 

    } 


    // No one assigned to this Phone Queue is in a ready state => "AgentsTalking":"number of agents on the phone","Status":"1" (Potentially can redistribute the phone) 
    if (request.Status == "1" && !string.IsNullOrEmpty(request.AgentsTalking) && request.AgentsTalking != "0") 
    { 
     //retry 
     throw new OutBoundAgentNotFoundException("<NEW MEWSSAGE HERE 1>"); 
    } 

    // No one assigned to this Phone Queue is in a ready state => "AgentsTalking":"0","Status":"1" (No one in the Call Center) 
    if (request.Status == "1" && !string.IsNullOrEmpty(request.AgentsTalking) && request.AgentsTalking == "0") 
    { 
     //retry 
     throw new OutBoundAgentNotFoundException("<NEW MEWSSAGE HERE 2>"); 
    } 
    // 'should' not get here 
    throw new OutBoundAgentNotFoundException("<NEW MEWSSAGE HERE 3>"); 
} 

在Windows服務處理程序的註冊

//This method is being called in response to a message being published by the 
//RabittMQ Broker (Queue mq:OutboundILeadPhone.inq) 
//The result of sucessuflully processing this message will result in a message being published to 
// (Queue mq:OutboundILeadPhone.outq) 
public object Post(OutboundILeadPhone request) 
{ 
    if (request == null) throw new ArgumentNullException("request"); 

    //By default there is only 1 worker thread (per message type) 
    //that's used to process the request, so you can just add a 
    //Thread.Sleep() in your Service to delay processing of the request 
    //as the next request only gets processed after the previous one has finished. 

    int delay = 2000; 
    Thread.Sleep(delay); //todo:smp configurable 

    var profiler = Profiler.Current; 
    using (profiler.Step("PhoneApi DirectApiServices POST OutboundILeadPhone")) 
    { 
     try 
     { 





     } 
     catch (Exception exception) 
     { 
      _log.Error(request.ToJson(), exception); 
      throw; 
     } 

    } 
    /*_log.Debug(profiler.GetTimingHierarchy());*/ 

    return null; 
} 

謝謝 斯蒂芬

回答

1

我剛剛committed a change將存儲在InnerException原始的異常和MQ錯誤處理程序現在被傳遞MessageHandler的處理消息讓你的錯誤回調現在可以訪問原來MqClient實例檢索的消息,這可以被用來NAK,則消息,例如:從MqAppHostTests

public CustomException LastCustomException; 

public void HandleMqCustomException(IMessageHandler mqHandler, 
    IMessage<MqCustomException> message, Exception ex) 
{ 
    LastCustomException = ex.InnerException as CustomException; 

    bool requeue = !(ex is UnRetryableMessagingException) 
     && message.RetryAttempts < 1; 

    if (requeue) 
    { 
     message.RetryAttempts++; 
    } 

    message.Error = ex.ToResponseStatus(); 
    mqHandler.MqClient.Nak(message, requeue: requeue, exception: ex); 
} 

這是是示出如何從服務和NAK檢索原始例外從原始MQ客戶端消息實例。

此更改可從v4.0.35 +即現在的available on MyGet

+0

謝謝!我會報告我的調查結果 – 2014-12-20 01:12:53