예제 #1
0
        private void PublishMessageAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes)
        {
            var command = processingCommand.Message;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("PublishApplicationMessageAsync",
                                                                  () => _messagePublisher.PublishAsync(message),
                                                                  currentRetryTimes => PublishMessageAsync(processingCommand, message, currentRetryTimes),
                                                                  result =>
            {
                NotifyCommandExecuted(processingCommand, CommandStatus.Success, message.GetTypeName(), _jsonSerializer.Serialize(message));
            },
                                                                  () => string.Format("[application message:[id:{0},type:{1}],command:[id:{2},type:{3}]]", message.Id, message.GetType().Name, command.Id, command.GetType().Name),
                                                                  errorMessage => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, typeof(string).FullName, errorMessage ?? "Publish application message async failed."),
                                                                  retryTimes);
        }
예제 #2
0
        private void PublishMessageAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes)
        {
            var command = processingCommand.Message;

            _ioHelper.TryAsyncActionRecursively("PublishApplicationMessageAsync",
                                                () => _applicationMessagePublisher.PublishAsync(message),
                                                currentRetryTimes => PublishMessageAsync(processingCommand, message, currentRetryTimes),
                                                result =>
            {
                CompleteCommand(processingCommand, CommandStatus.Success, message.GetTypeName(), _jsonSerializer.Serialize(message));
            },
                                                () => string.Format("[application message:[id:{0},type:{1}],command:[id:{2},type:{3}]]", message.Id, message.GetType().Name, command.Id, command.GetType().Name),
                                                errorMessage =>
            {
                _logger.Fatal(string.Format("Publish application message has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage));
            },
                                                retryTimes, true);
        }