Exemplo n.º 1
0
        private void HandleMessageAsync(DisptachingMessage dispatchingMessage, IMessageHandlerProxy handlerProxy, int handlerTypeCode, int messageTypeCode, int retryTimes)
        {
            var message = dispatchingMessage.Message;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("HandleMessageAsync",
                                                                  () => handlerProxy.HandleAsync(message),
                                                                  currentRetryTimes => HandleMessageAsync(dispatchingMessage, handlerProxy, handlerTypeCode, messageTypeCode, currentRetryTimes),
                                                                  result =>
            {
                var messageHandleRecord = new MessageHandleRecord
                {
                    MessageId       = message.Id,
                    HandlerTypeCode = handlerTypeCode,
                    MessageTypeCode = messageTypeCode,
                    Timestamp       = DateTime.Now
                };
                var sequenceMessage = message as ISequenceMessage;
                if (sequenceMessage != null)
                {
                    messageHandleRecord.AggregateRootTypeCode = sequenceMessage.AggregateRootTypeCode;
                    messageHandleRecord.AggregateRootId       = sequenceMessage.AggregateRootId;
                    messageHandleRecord.Version = sequenceMessage.Version;
                }

                AddMessageHandledRecordAsync(dispatchingMessage, messageHandleRecord, handlerProxy.GetInnerHandler().GetType(), handlerTypeCode, 0);
            },
                                                                  () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerProxy.GetInnerHandler().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void HandleMessageAsync(DisptachingMessage dispatchingMessage, IMessageHandlerProxy handlerProxy, int handlerTypeCode, int messageTypeCode, int retryTimes)
        {
            var message = dispatchingMessage.Message;

            _ioHelper.TryAsyncActionRecursively<AsyncTaskResult>("HandleMessageAsync",
            () => handlerProxy.HandleAsync(message),
            currentRetryTimes => HandleMessageAsync(dispatchingMessage, handlerProxy, handlerTypeCode, messageTypeCode, currentRetryTimes),
            result =>
            {
                var messageHandleRecord = new MessageHandleRecord
                {
                    MessageId = message.Id,
                    HandlerTypeCode = handlerTypeCode,
                    MessageTypeCode = messageTypeCode,
                    Timestamp = DateTime.Now
                };
                var sequenceMessage = message as ISequenceMessage;
                if (sequenceMessage != null)
                {
                    messageHandleRecord.AggregateRootTypeCode = sequenceMessage.AggregateRootTypeCode;
                    messageHandleRecord.AggregateRootId = sequenceMessage.AggregateRootId;
                    messageHandleRecord.Version = sequenceMessage.Version;
                }

                AddMessageHandledRecordAsync(dispatchingMessage, messageHandleRecord, handlerProxy.GetInnerHandler().GetType(), handlerTypeCode, 0);
            },
            () => string.Format("[messageId:{0}, messageType:{1}, handlerType:{2}]", message.Id, message.GetType().Name, handlerProxy.GetInnerHandler().GetType().Name),
            null,
            retryTimes,
            true);
        }