示例#1
0
            public void Enrich(AuditEnricherContext context)
            {
                if (context.Headers.TryGetValue(Headers.ConversationId, out var conversationId))
                {
                    context.Metadata.Add("ConversationId", conversationId);
                }

                if (context.Headers.TryGetValue(Headers.RelatedTo, out var relatedToId))
                {
                    context.Metadata.Add("RelatedToId", relatedToId);
                }
            }
            public void Enrich(AuditEnricherContext context)
            {
                var headers           = context.Headers;
                var metadata          = context.Metadata;
                var processingEnded   = DateTime.MinValue;
                var timeSent          = DateTime.MinValue;
                var processingStarted = DateTime.MinValue;

                if (headers.TryGetValue(Headers.TimeSent, out var timeSentValue))
                {
                    timeSent = DateTimeExtensions.ToUtcDateTime(timeSentValue);
                    metadata.Add("TimeSent", timeSent);
                }

                if (headers.TryGetValue(Headers.ProcessingStarted, out var processingStartedValue))
                {
                    processingStarted = DateTimeExtensions.ToUtcDateTime(processingStartedValue);
                }

                if (headers.TryGetValue(Headers.ProcessingEnded, out var processingEndedValue))
                {
                    processingEnded = DateTimeExtensions.ToUtcDateTime(processingEndedValue);
                }

                var criticalTime = TimeSpan.Zero;

                if (processingEnded != DateTime.MinValue && timeSent != DateTime.MinValue)
                {
                    criticalTime = processingEnded - timeSent;
                }

                metadata.Add("CriticalTime", criticalTime);

                var processingTime = TimeSpan.Zero;

                if (processingEnded != DateTime.MinValue && processingStarted != DateTime.MinValue)
                {
                    processingTime = processingEnded - processingStarted;
                }

                metadata.Add("ProcessingTime", processingTime);

                var deliveryTime = TimeSpan.Zero;

                if (processingStarted != DateTime.MinValue && timeSent != DateTime.MinValue)
                {
                    deliveryTime = processingStarted - timeSent;
                }

                metadata.Add("DeliveryTime", deliveryTime);
            }
示例#3
0
        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);
            }
        }
示例#4
0
            public void Enrich(AuditEnricherContext context)
            {
                var    isSystemMessage = false;
                string messageType     = null;

                if (context.Headers.ContainsKey(Headers.ControlMessageHeader))
                {
                    isSystemMessage = true;
                }

                if (context.Headers.TryGetValue(Headers.EnclosedMessageTypes, out var enclosedMessageTypes))
                {
                    messageType     = GetMessageType(enclosedMessageTypes);
                    isSystemMessage = DetectSystemMessage(messageType);
                    context.Metadata.Add("SearchableMessageType", messageType.Replace(".", " ").Replace("+", " "));
                }

                context.Metadata.Add("IsSystemMessage", isSystemMessage);
                context.Metadata.Add("MessageType", messageType);
            }
        async Task ProcessAuditMessage(MessageContext context)
        {
            if (!context.Headers.TryGetValue(Headers.MessageId, out var messageId))
            {
                messageId = DeterministicGuid.MakeId(context.MessageId).ToString();
            }

            try
            {
                var metadata = new ConcurrentDictionary <string, object>
                {
                    ["MessageId"]     = messageId,
                    ["MessageIntent"] = context.Headers.MessageIntent()
                };

                var commandsToEmit  = new List <ICommand>();
                var enricherContext = new AuditEnricherContext(context.Headers, commandsToEmit, metadata);

                // ReSharper disable once LoopCanBeConvertedToQuery
                foreach (var enricher in enrichers)
                {
                    enricher.Enrich(enricherContext);
                }

                await bodyStorageEnricher.StoreAuditMessageBody(context.Body, context.Headers, metadata)
                .ConfigureAwait(false);

                var auditMessage = new ProcessedMessage(context.Headers, new Dictionary <string, object>(metadata))
                {
                    Id = $"ProcessedMessages/{context.Headers.ProcessingId()}"
                };

                foreach (var commandToEmit in commandsToEmit)
                {
                    await messageSession.Send(commandToEmit)
                    .ConfigureAwait(false);
                }

                context.Extensions.Set(auditMessage);
                if (metadata.TryGetValue("SendingEndpoint", out var sendingEndpoint))
                {
                    context.Extensions.Set("SendingEndpoint", (EndpointDetails)sendingEndpoint);
                }

                if (metadata.TryGetValue("ReceivingEndpoint", out var receivingEndpoint))
                {
                    context.Extensions.Set("ReceivingEndpoint", (EndpointDetails)receivingEndpoint);
                }

                context.Extensions.Set("AuditType", "ProcessedMessage");
            }
            catch (Exception e)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug($"Processing of message '{messageId}' failed.", e);
                }

                context.GetTaskCompletionSource().TrySetException(e);
            }
        }