예제 #1
0
        private void DispatchMessageToHandlerAsync(DisptachingMessage dispatchingMessage, IMessageHandlerProxy handlerProxy, int retryTimes)
        {
            var message               = dispatchingMessage.Message;
            var messageTypeCode       = _typeCodeProvider.GetTypeCode(message.GetType());
            var handlerType           = handlerProxy.GetInnerHandler().GetType();
            var handlerTypeCode       = _typeCodeProvider.GetTypeCode(handlerType);
            var aggregateRootTypeCode = message is ISequenceMessage ? ((ISequenceMessage)message).AggregateRootTypeCode : 0;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <bool> >("IsRecordExistAsync",
                                                                          () => _messageHandleRecordStore.IsRecordExistAsync(message.Id, handlerTypeCode, aggregateRootTypeCode),
                                                                          currentRetryTimes => DispatchMessageToHandlerAsync(dispatchingMessage, handlerProxy, currentRetryTimes),
                                                                          result =>
            {
                if (result.Data)
                {
                    dispatchingMessage.RemoveHandledHandler(handlerTypeCode);
                }
                else
                {
                    HandleMessageAsync(dispatchingMessage, handlerProxy, handlerTypeCode, messageTypeCode, 0);
                }
            },
                                                                          () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerType.Name),
                                                                          null,
                                                                          retryTimes,
                                                                          true);
        }
예제 #2
0
        private void AddMessageHandledRecordAsync(DisptachingMessage dispatchingMessage, MessageHandleRecord messageHandleRecord, Type handlerType, int handlerTypeCode, int retryTimes)
        {
            var message = dispatchingMessage.Message;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("AddMessageHandledRecordAsync",
                                                                  () => _messageHandleRecordStore.AddRecordAsync(messageHandleRecord),
                                                                  currentRetryTimes => AddMessageHandledRecordAsync(dispatchingMessage, messageHandleRecord, handlerType, handlerTypeCode, currentRetryTimes),
                                                                  result =>
            {
                dispatchingMessage.RemoveHandledHandler(handlerTypeCode);
                _logger.DebugFormat("Message handled success, handlerType:{0}, messageType:{1}, messageId:{2}", handlerType.Name, message.GetType().Name, message.Id);
            },
                                                                  () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerType.Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
예제 #3
0
        private void AddMessageHandledRecordAsync(DisptachingMessage dispatchingMessage, MessageHandleRecord messageHandleRecord, Type handlerType, int handlerTypeCode, int retryTimes)
        {
            var message = dispatchingMessage.Message;

            _ioHelper.TryAsyncActionRecursively<AsyncTaskResult>("AddMessageHandledRecordAsync",
            () => _messageHandleRecordStore.AddRecordAsync(messageHandleRecord),
            currentRetryTimes => AddMessageHandledRecordAsync(dispatchingMessage, messageHandleRecord, handlerType, handlerTypeCode, currentRetryTimes),
            result =>
            {
                dispatchingMessage.RemoveHandledHandler(handlerTypeCode);
                _logger.DebugFormat("Message handled success, handlerType:{0}, messageType:{1}, messageId:{2}", handlerType.Name, message.GetType().Name, message.Id);
            },
            () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerType.Name),
            null,
            retryTimes,
            true);
        }
예제 #4
0
        private void DispatchMessageToHandlerAsync(DisptachingMessage dispatchingMessage, IMessageHandlerProxy handlerProxy, int retryTimes)
        {
            var message = dispatchingMessage.Message;
            var messageTypeCode = _typeCodeProvider.GetTypeCode(message.GetType());
            var handlerType = handlerProxy.GetInnerHandler().GetType();
            var handlerTypeCode = _typeCodeProvider.GetTypeCode(handlerType);
            var aggregateRootTypeCode = message is ISequenceMessage ? ((ISequenceMessage)message).AggregateRootTypeCode : 0;

            _ioHelper.TryAsyncActionRecursively<AsyncTaskResult<bool>>("IsRecordExistAsync",
            () => _messageHandleRecordStore.IsRecordExistAsync(message.Id, handlerTypeCode, aggregateRootTypeCode),
            currentRetryTimes => DispatchMessageToHandlerAsync(dispatchingMessage, handlerProxy, currentRetryTimes),
            result =>
            {
                if (result.Data)
                {
                    dispatchingMessage.RemoveHandledHandler(handlerTypeCode);
                }
                else
                {
                    HandleMessageAsync(dispatchingMessage, handlerProxy, handlerTypeCode, messageTypeCode, 0);
                }
            },
            () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerType.Name),
            null,
            retryTimes,
            true);
        }