public async Task Ingest(ProcessAuditMessageContext context) { if (log.IsDebugEnabled) { log.DebugFormat("Ingesting audit message {0}", context.Message.MessageId); } await auditPersister.Persist(context).ConfigureAwait(false); if (settings.ForwardAuditMessages) { await messageForwarder.Forward(context.Message, settings.AuditLogQueue) .ConfigureAwait(false); } }
public async Task Persist(ProcessAuditMessageContext context) { if (!context.Message.Headers.TryGetValue(Headers.MessageId, out var messageId)) { messageId = DeterministicGuid.MakeId(context.Message.MessageId).ToString(); } var metadata = new ConcurrentDictionary <string, object> { ["MessageId"] = messageId, ["MessageIntent"] = context.Message.Headers.MessageIntent() }; var commandsToEmit = new List <ICommand>(); var enricherContext = new AuditEnricherContext(context.Message.Headers, commandsToEmit, metadata); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var enricher in enrichers) { enricher.Enrich(enricherContext); } await bodyStorageEnricher.StoreAuditMessageBody(context.Message.Body, context.Message.Headers, metadata) .ConfigureAwait(false); var auditMessage = new ProcessedMessage(context.Message.Headers, new Dictionary <string, object>(metadata)) { // We do this so Raven does not spend time assigning a hilo key Id = $"ProcessedMessages/{Guid.NewGuid()}" }; using (var session = store.OpenAsyncSession()) { await session.StoreAsync(auditMessage) .ConfigureAwait(false); await session.SaveChangesAsync() .ConfigureAwait(false); } foreach (var commandToEmit in commandsToEmit) { await context.MessageSession.Send(commandToEmit) .ConfigureAwait(false); } }
Task OnAuditMessage(ProcessAuditMessageContext context) { return(auditIngestor.Ingest(context)); }