public override async Task InvokeAsync <TCommand>( TCommand command, CommandRequestRegistration <TCommand> registration, HttpContext context) { this.logger.LogInformation($"{{LogKey:l}} command request dispatch (name={registration.CommandType.PrettyName()}, id={command.Id}, type=queue)", LogKeys.AppCommand); //var wrapper = new CommandWrapper().SetCommand<TCommand>(command); var wrapper = new CommandRequestWrapper().SetCommand(command); await this.queue.EnqueueAsync(wrapper).AnyContext(); var metrics = await this.queue.GetMetricsAsync().AnyContext(); this.logger.LogInformation($"{{LogKey:l}} request command queue (enqueued=#{metrics.Enqueued}, queued=#{metrics.Queued})", LogKeys.AppCommand); this.logger.LogInformation($"queued COMMAND: {command.Dump()}"); await context.Response.Location($"naos/commands/{command.Id}/response").AnyContext(); await context.Response.Header(CommandRequestHeaders.CommandId, command.Id).AnyContext(); await this.StoreCommand(wrapper).AnyContext(); // the extension chain is terminated here }
private async Task StoreCommand(CommandRequestWrapper wrapper) { if (this.storage != null) { // optionaly store the command/response so it can later be retrieved by the client (because the command was queued with no direct response) await this.storage.SaveAsync(wrapper).AnyContext(); } }
public async Task <bool> SaveAsync(CommandRequestWrapper commandRequest) { return(await this.storage.SaveFileObjectAsync($"{commandRequest.Id}.json", commandRequest, this.serializer).AnyContext()); }