/// <summary>
        /// Handle retry limit exceeded
        /// </summary>
        /// <param name="data"></param>
        public void HandleRetryLimitExceeded(DispatchData data)
        {
            // handle retry limit only when we get exception or fault message
            Contract.Requires(data.Exception != null ||
                              (data.ReplyMessage != null && data.ReplyMessage.IsFault == true),
                              "Retry Limit Exceeded when there is exception or fault message");

            int retryLimit = this.sharedData.Config.LoadBalancing.MessageResendLimit;

            BrokerTracing.EtwTrace.LogBackendResponseReceivedRetryLimitExceed(data.SessionId, data.TaskId, data.MessageId, retryLimit);

            // Initialize retry error and fault reason
            RetryOperationError retryError;
            FaultReason         faultReason;

            if (data.Exception != null)
            {
                // generate fault exception from original exception
                retryError = new RetryOperationError(data.Exception.Message);

                string exceptionFaultReason = String.Format(SR.RetryLimitExceeded, retryLimit + 1, data.Exception.Message);
                faultReason = new FaultReason(exceptionFaultReason);
            }
            else
            {
                #region Debug Failure Test
                SimulateFailure.FailOperation(1);
                #endregion

                // generate fault exception from original reply
                MessageFault messageFault = MessageFault.CreateFault(data.ReplyMessage, Constant.MaxBufferSize);
                retryError  = messageFault.GetDetail <RetryOperationError>();
                faultReason = messageFault.Reason;

                // close original reply message
                data.ReplyMessage.Close();
            }

            retryError.RetryCount          = retryLimit + 1;
            retryError.LastFailedServiceId = data.TaskId;

            // Construct the new exception
            FaultException <RetryOperationError> faultException = new FaultException <RetryOperationError>(retryError, faultReason, Constant.RetryLimitExceedFaultCode, RetryOperationError.Action);

            data.Exception = faultException;
            this.responseQueueAdapter.PutResponseBack(data);
        }
Пример #2
0
        /// <summary>
        /// Try to parse broker exception from the message
        /// </summary>
        /// <param name="messageFault">indicating the message fault</param>
        /// <param name="action">indicating the action</param>
        /// <param name="brokerException">output the broker exception</param>
        /// <returns>returns a value indicating whether successfully parsed out broker exception</returns>
        private static bool TryParseBrokerException(MessageFault messageFault, string action, out Exception brokerException)
        {
            switch (action)
            {
            case AuthenticationFailure.Action:
                AuthenticationFailure af = messageFault.GetDetail <AuthenticationFailure>();
                brokerException = new AuthenticationException(String.Format(SR.Broker_AuthenticationFailure, af.UserName));
                return(true);

            case RetryOperationError.Action:
                RetryOperationError rle = messageFault.GetDetail <RetryOperationError>();
                brokerException = new RetryOperationException(String.Format(SR.Broker_RetryLimitExceeded, rle.RetryCount, rle.Reason), rle.Reason);
                return(true);

            case SessionFault.Action:
                SessionFault fault = messageFault.GetDetail <SessionFault>();
                brokerException = Utility.TranslateFaultException(new FaultException <SessionFault>(fault, messageFault.Reason));
                return(true);

            default:
                brokerException = null;
                return(false);
            }
        }