private void DispatchThreeMessageToHandlerAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy3 handlerProxy, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var handlerType     = handlerProxy.GetInnerObject().GetType();
            var handlerTypeName = _typeNameProvider.GetTypeName(handlerType);

            HandleThreeMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, 0);
        }
        private void DispatchThreeMessageToHandlerAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy3 handlerProxy, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var messages              = multiMessageDispatching.Messages;
            var message1              = messages[0];
            var message2              = messages[1];
            var message3              = messages[2];
            var handlerType           = handlerProxy.GetInnerObject().GetType();
            var handlerTypeName       = _typeNameProvider.GetTypeName(handlerType);
            var aggregateRootTypeName = message1 is ISequenceMessage ? ((ISequenceMessage)message1).AggregateRootTypeName : null;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <bool> >("IsThreeMessageRecordExistAsync",
                                                                          () => _messageHandleRecordStore.IsRecordExistAsync(message1.Id, message2.Id, message3.Id, handlerTypeName, aggregateRootTypeName),
                                                                          currentRetryTimes => DispatchThreeMessageToHandlerAsync(multiMessageDispatching, handlerProxy, queueHandler, currentRetryTimes),
                                                                          result =>
            {
                if (result.Data)
                {
                    multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                    if (queueHandler != null)
                    {
                        queueHandler.OnHandlerFinished(handlerProxy);
                    }
                }
                else
                {
                    HandleThreeMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, 0);
                }
            },
                                                                          () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                                          null,
                                                                          retryTimes,
                                                                          true);
        }
        private void HandleThreeMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy3 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];
            var message3 = messages[2];

            _ioHelper.TryAsyncActionRecursively("HandleThreeMessageAsync",
                                                () => handlerProxy.HandleAsync(message1, message2, message3),
                                                currentRetryTimes => HandleThreeMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                result =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                _logger.DebugFormat("ThreeMessage handled success, [messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerTypeName);
            },
                                                () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                errorMessage =>
            {
                _logger.Fatal(string.Format("Handle three message has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage));
            },
                                                retryTimes, true);
        }
        private void AddThreeMessageHandledRecordAsync(MultiMessageDisptaching multiMessageDispatching, ThreeMessageHandleRecord messageHandleRecord, string handlerTypeName, IMessageHandlerProxy3 handlerProxy, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("AddThreeMessageHandledRecordAsync",
                                                                  () => _messageHandleRecordStore.AddRecordAsync(messageHandleRecord),
                                                                  currentRetryTimes => AddThreeMessageHandledRecordAsync(multiMessageDispatching, messageHandleRecord, handlerTypeName, handlerProxy, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("ThreeMessage handled success, [messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name);
                }
            },
                                                                  () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
        private void HandleThreeMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy3 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];
            var message3 = messages[2];

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("HandleTwoMessageAsync",
                                                                  () => handlerProxy.HandleAsync(message1, message2, message3),
                                                                  currentRetryTimes => HandleThreeMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                var message1TypeName    = _typeNameProvider.GetTypeName(message1.GetType());
                var message2TypeName    = _typeNameProvider.GetTypeName(message2.GetType());
                var message3TypeName    = _typeNameProvider.GetTypeName(message3.GetType());
                var messageHandleRecord = new ThreeMessageHandleRecord
                {
                    MessageId1       = message1.Id,
                    MessageId2       = message2.Id,
                    MessageId3       = message3.Id,
                    Message1TypeName = message1TypeName,
                    Message2TypeName = message2TypeName,
                    Message3TypeName = message3TypeName,
                    HandlerTypeName  = handlerTypeName,
                    CreatedOn        = DateTime.Now
                };
                var sequenceMessage = message1 as ISequenceMessage;
                if (sequenceMessage != null)
                {
                    messageHandleRecord.AggregateRootTypeName = sequenceMessage.AggregateRootTypeName;
                    messageHandleRecord.AggregateRootId       = sequenceMessage.AggregateRootStringId;
                    messageHandleRecord.Version = sequenceMessage.Version;
                }

                AddThreeMessageHandledRecordAsync(multiMessageDispatching, messageHandleRecord, handlerTypeName, handlerProxy, queueHandler, 0);
            },
                                                                  () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
Exemple #6
0
        private void HandleThreeMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy3 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy3> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];
            var message3 = messages[2];

            _ioHelper.TryAsyncActionRecursivelyWithoutResult("HandleThreeMessageAsync",
                                                             () => handlerProxy.HandleAsync(message1, message2, message3),
                                                             currentRetryTimes => HandleThreeMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                             () =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                _logger.InfoFormat("ThreeMessage handled success, [messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerTypeName);
            },
                                                             () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                             null,
                                                             retryTimes, true);
        }