private void HandleSingleMessageAsync(SingleMessageDisptaching singleMessageDispatching, IMessageHandlerProxy1 handlerProxy, string handlerTypeName, string messageTypeName, QueuedHandler <IMessageHandlerProxy1> queueHandler, int retryTimes)
        {
            var message = singleMessageDispatching.Message;

            _ioHelper.TryAsyncActionRecursively("HandleSingleMessageAsync",
                                                () => handlerProxy.HandleAsync(message),
                                                currentRetryTimes => HandleSingleMessageAsync(singleMessageDispatching, handlerProxy, handlerTypeName, messageTypeName, queueHandler, currentRetryTimes),
                                                result =>
            {
                singleMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("Message handled success, handlerType:{0}, messageType:{1}, messageId:{2}", handlerTypeName, message.GetType().Name, message.Id);
                }
            },
                                                () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerProxy.GetInnerObject().GetType().Name),
                                                errorMessage =>
            {
                _logger.Fatal(string.Format("Handle single message has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage));
            },
                                                retryTimes);
        }
        private void HandleSingleMessageAsync(SingleMessageDisptaching singleMessageDispatching, IMessageHandlerProxy1 handlerProxy, string handlerTypeName, string messageTypeName, QueuedHandler <IMessageHandlerProxy1> queueHandler, int retryTimes)
        {
            var message = singleMessageDispatching.Message;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("HandleSingleMessageAsync",
                                                                  () => handlerProxy.HandleAsync(message),
                                                                  currentRetryTimes => HandleSingleMessageAsync(singleMessageDispatching, handlerProxy, handlerTypeName, messageTypeName, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                var messageHandleRecord = new MessageHandleRecord
                {
                    MessageId       = message.Id,
                    MessageTypeName = messageTypeName,
                    HandlerTypeName = handlerTypeName,
                    CreatedOn       = DateTime.Now
                };
                var sequenceMessage = message as ISequenceMessage;
                if (sequenceMessage != null)
                {
                    messageHandleRecord.AggregateRootTypeName = sequenceMessage.AggregateRootTypeName;
                    messageHandleRecord.AggregateRootId       = sequenceMessage.AggregateRootStringId;
                    messageHandleRecord.Version = sequenceMessage.Version;
                }

                AddMessageHandledRecordAsync(singleMessageDispatching, messageHandleRecord, handlerProxy.GetInnerObject().GetType(), handlerTypeName, handlerProxy, queueHandler, 0);
            },
                                                                  () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerProxy.GetInnerObject().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
        private void HandleSingleMessageAsync(SingleMessageDisptaching singleMessageDispatching, IMessageHandlerProxy1 handlerProxy, string handlerTypeName, string messageTypeName, QueuedHandler <IMessageHandlerProxy1> queueHandler, int retryTimes)
        {
            var message = singleMessageDispatching.Message;

            _ioHelper.TryAsyncActionRecursivelyWithoutResult("HandleSingleMessageAsync",
                                                             () => handlerProxy.HandleAsync(message),
                                                             currentRetryTimes => HandleSingleMessageAsync(singleMessageDispatching, handlerProxy, handlerTypeName, messageTypeName, queueHandler, currentRetryTimes),
                                                             () =>
            {
                singleMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                _logger.DebugFormat("Message handled success, handlerType:{0}, messageType:{1}, messageId:{2}", handlerTypeName, message.GetType().Name, message.Id);
            },
                                                             () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerProxy.GetInnerObject().GetType().Name),
                                                             null,
                                                             retryTimes, true);
        }