public Outcome(bool Succeeded, P Payload, IApplicationMessage Description) { this.Succeeded = Succeeded; this._Payload = Payload; this.Description = Description; this.Terminal = not(Succeeded); }
private void CommitChangesAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes) { var command = processingCommand.Message; var handledCommand = new HandledCommand(command.Id, command.AggregateRootId, message); _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <CommandAddResult> >("AddCommandAsync", () => _commandStore.AddAsync(handledCommand), currentRetryTimes => CommitChangesAsync(processingCommand, message, currentRetryTimes), result => { var commandAddResult = result.Data; if (commandAddResult == CommandAddResult.Success) { PublishMessageAsync(processingCommand, message, 0); } else if (commandAddResult == CommandAddResult.DuplicateCommand) { HandleDuplicatedCommandAsync(processingCommand, 0); } else { _logger.ErrorFormat("Add command async failed, commandType:{0}, commandId:{1}, aggregateRootId:{2}", command.GetType().Name, command.Id, command.AggregateRootId); NotifyCommandExecuted(processingCommand, CommandStatus.Failed, typeof(string).FullName, "Add command async failed."); } }, () => string.Format("[handledCommand:{0}]", handledCommand), errorMessage => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, typeof(string).Name, errorMessage ?? "Add command async failed."), retryTimes); }
Outcome(bool Succeeded, P Payload, IApplicationMessage Description, bool Terminal) { this.Succeeded = Succeeded; this._Payload = Payload; this.Description = Description; this.Terminal = Terminal; }
public void Notify(IApplicationMessage messageNotifier, string message) { if (messageNotifier != null && !string.IsNullOrEmpty(message)) { messageNotifier.SendMessage(message); } }
/// <summary>Parameterized constructor. /// </summary> /// <param name="command"></param> /// <param name="aggregateRootId"></param> /// <param name="aggregateRootTypeCode"></param> /// <param name="message"></param> public HandledCommand(ICommand command, string aggregateRootId = null, int aggregateRootTypeCode = 0, IApplicationMessage message = null) { Command = command; AggregateRootId = aggregateRootId; AggregateRootTypeCode = aggregateRootTypeCode; Message = message; }
private void CommitChangesAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes) { var command = processingCommand.Message; var handledCommand = new HandledCommand( command, aggregateRootId: command.AggregateRootId, message: message); _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <CommandAddResult> >("AddCommandAsync", () => _commandStore.AddAsync(handledCommand), currentRetryTimes => CommitChangesAsync(processingCommand, message, currentRetryTimes), result => { var commandAddResult = result.Data; if (commandAddResult == CommandAddResult.Success) { PublishMessageAsync(processingCommand, message, 0); } else if (commandAddResult == CommandAddResult.DuplicateCommand) { HandleDuplicatedCommandAsync(processingCommand, 0); } else { NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Add command async failed."); } }, () => string.Format("[handledCommand:{0}]", handledCommand), () => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Add command async failed."), retryTimes); }
public Outcome(bool Succeeded, IApplicationMessage Description) { this.Succeeded = false; if (Description == null) { throw new ArgumentNullException(nameof(Description)); } this.Description = Description; this._Payload = default(P); this.Terminal = not(Succeeded); }
public Outcome(P Payload) { this.Succeeded = true; if (Payload == null) { throw new ArgumentNullException(nameof(Payload)); } this._Payload = Payload; this.Description = ApplicationMessage.Empty; this.Terminal = not(Succeeded); }
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, null, null); }, () => string.Format("[application message:[id:{0},type:{1}],command:[id:{2},type:{3}]]", message.Id, message.GetType().Name, command.Id, command.GetType().Name), () => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Publish application message async failed."), retryTimes); }
private Task PublishMessageAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes, TaskCompletionSource <bool> taskSource) { var command = processingCommand.Message; _ioHelper.TryAsyncActionRecursivelyWithoutResult("PublishApplicationMessageAsync", () => _applicationMessagePublisher.PublishAsync(message), currentRetryTimes => PublishMessageAsync(processingCommand, message, currentRetryTimes, taskSource), async() => { await CompleteCommand(processingCommand, CommandStatus.Success, message.GetType().FullName, _jsonSerializer.Serialize(message)).ConfigureAwait(false); taskSource.SetResult(true); }, () => string.Format("[application message:[id:{0},type:{1}],command:[id:{2},type:{3}]]", message.Id, message.GetType().Name, command.Id, command.GetType().Name), null, retryTimes, true); return(taskSource.Task); }
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.GetType().FullName, _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); }
private void CommitChangesAsync(ProcessingCommand processingCommand, bool success, IApplicationMessage message, string errorMessage) { if (success) { if (message != null) { PublishMessageAsync(processingCommand, message, 0); } else { CompleteCommand(processingCommand, CommandStatus.Success, null, null); } } else { CompleteCommand(processingCommand, CommandStatus.Failed, typeof(string).FullName, errorMessage); } }
/// <summary>Parameterized constructor. /// </summary> /// <param name="commandId"></param> /// <param name="aggregateRootId"></param> /// <param name="message"></param> public HandledCommand(string commandId, string aggregateRootId = null, IApplicationMessage message = null) { CommandId = commandId; AggregateRootId = aggregateRootId; Message = message; }
public void Trigger(IApplicationMessage applicationMessage) { Messenger.Trigger(applicationMessage); }
async Task PublishApplicationMessageAsync(ProcessingCommand processingCommand, IApplicationMessage applicationMessage) { var result = await Policy .Handle <Exception>() .OrResult <AsyncExecutedResult>(r => !r.Succeeded) .WaitAndRetryForeverAsync( retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (delegateResult, retryCount, retryAttempt) => logger.LogError(delegateResult.Exception ?? delegateResult.Result.Exception, $"命令产生的应用消息发布失败,重试。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}, RetryCount = {retryCount}, RetryAttempt = {retryAttempt}]")) .ExecuteAsync(() => applicationMessagePublisher.PublishAsync(applicationMessage)); if (result.Succeeded) { logger.LogDebug($"命令产生的应用消息发布成功。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}]"); await processingCommand.OnQueueProcessedAsync(CommandExecutedStatus.Succeeded, objectSerializer.Serialize(applicationMessage), applicationMessage.GetTag()); } else { logger.LogDebug(result.Exception, $"命令产生的应用消息发布失败。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}]"); } }
private void CommitChangesAsync(ProcessingCommand processingCommand, bool success, IApplicationMessage message, string errorMessage, int retryTimes) { var command = processingCommand.Message; var handledCommand = new HandledCommand(command.Id, command.AggregateRootId, message); _ioHelper.TryAsyncActionRecursively("AddCommandAsync", () => _commandStore.AddAsync(handledCommand), currentRetryTimes => CommitChangesAsync(processingCommand, success, message, errorMessage, currentRetryTimes), result => { var commandAddResult = result.Data; if (commandAddResult == CommandAddResult.Success) { if (success) { if (message != null) { PublishMessageAsync(processingCommand, message, 0); } else { CompleteCommand(processingCommand, CommandStatus.Success, null, null); } } else { CompleteCommand(processingCommand, CommandStatus.Failed, typeof(string).FullName, errorMessage); } } else if (commandAddResult == CommandAddResult.DuplicateCommand) { HandleDuplicatedCommandAsync(processingCommand, 0); } }, () => string.Format("[handledCommand:{0}]", handledCommand), error => { _logger.Fatal(string.Format("Add command has unknown exception, the code should not be run to here, errorMessage: {0}", error)); }, retryTimes, true); }
public void Trigger(IApplicationMessage message) { applicationMessageEvent.Trigger(message); }
public ProcessingApplicationMessage(IApplicationMessage applicationMessage) => ApplicationMessage = applicationMessage;
public ProcessingApplicationMessage(IApplicationMessage message, IMessageProcessContext processContext) { Message = message; _processContext = processContext; }
private async Task CommitChangesAsync(ProcessingCommand processingCommand, bool success, IApplicationMessage message, string errorMessage, TaskCompletionSource <bool> taskSource) { if (success) { if (message != null) { message.MergeItems(processingCommand.Message.Items); await PublishMessageAsync(processingCommand, message, 0, new TaskCompletionSource <bool>()).ConfigureAwait(false); taskSource.SetResult(true); } else { await CompleteCommand(processingCommand, CommandStatus.Success, null, null).ConfigureAwait(false); taskSource.SetResult(true); } } else { await CompleteCommand(processingCommand, CommandStatus.Failed, typeof(string).FullName, errorMessage).ConfigureAwait(false); taskSource.SetResult(true); } }
public Task PublishAsync(IApplicationMessage message) { return(Task.CompletedTask); }
public void Trigger(IApplicationMessage message) { Events(message); }
public void SetApplicationMessage(IApplicationMessage applicationMessage) { _applicationMessage = applicationMessage; }
public void SendLocal(IApplicationMessage applicationEvent) { var queuePath = String.Format(Config.Get <string>("msmqNameTmpl"), Environment.MachineName); //MassTransitServiceBus.GetSendEndpoint(new Uri(queuePath)).Start(); .Send(applicationEvent); }
public Task <AsyncTaskResult> PublishAsync(IApplicationMessage message) { return(_successResultTask); }