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

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

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <bool> >("IsTwoMessageRecordExistAsync",
                                                                          () => _messageHandleRecordStore.IsRecordExistAsync(message1.Id, message2.Id, handlerTypeName, aggregateRootTypeName),
                                                                          currentRetryTimes => DispatchTwoMessageToHandlerAsync(multiMessageDispatching, handlerProxy, queueHandler, currentRetryTimes),
                                                                          result =>
            {
                if (result.Data)
                {
                    multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                    if (queueHandler != null)
                    {
                        queueHandler.OnHandlerFinished(handlerProxy);
                    }
                }
                else
                {
                    HandleTwoMessageAsync(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 HandleTwoMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy2 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];

            _ioHelper.TryAsyncActionRecursively("HandleTwoMessageAsync",
                                                () => handlerProxy.HandleAsync(message1, message2),
                                                currentRetryTimes => HandleTwoMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                result =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                _logger.DebugFormat("TwoMessage 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 two message has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage));
            },
                                                retryTimes, true);
        }
        private void AddTwoMessageHandledRecordAsync(MultiMessageDisptaching multiMessageDispatching, TwoMessageHandleRecord messageHandleRecord, string handlerTypeName, IMessageHandlerProxy2 handlerProxy, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("AddTwoMessageHandledRecordAsync",
                                                                  () => _messageHandleRecordStore.AddRecordAsync(messageHandleRecord),
                                                                  currentRetryTimes => AddTwoMessageHandledRecordAsync(multiMessageDispatching, messageHandleRecord, handlerTypeName, handlerProxy, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("TwoMessage 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 HandleTwoMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy2 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("HandleTwoMessageAsync",
                                                                  () => handlerProxy.HandleAsync(message1, message2),
                                                                  currentRetryTimes => HandleTwoMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                var message1TypeName    = _typeNameProvider.GetTypeName(message1.GetType());
                var message2TypeName    = _typeNameProvider.GetTypeName(message2.GetType());
                var messageHandleRecord = new TwoMessageHandleRecord
                {
                    MessageId1       = message1.Id,
                    MessageId2       = message2.Id,
                    Message1TypeName = message1TypeName,
                    Message2TypeName = message2TypeName,
                    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;
                }

                AddTwoMessageHandledRecordAsync(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);
        }
Esempio n. 6
0
        private void HandleTwoMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy2 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];

            _ioHelper.TryAsyncActionRecursivelyWithoutResult("HandleTwoMessageAsync",
                                                             () => handlerProxy.HandleAsync(message1, message2),
                                                             currentRetryTimes => HandleTwoMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                             () =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                _logger.InfoFormat("TwoMessage 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);
        }