Task IMessageAuditStore.StoreMessage <T>(T message, MessageAuditMetadata metadata)
        {
            var auditRecord            = AuditRecord.Create(message, metadata, _partitionKeyFormatter);
            var insertOrMergeOperation = TableOperation.InsertOrMerge(auditRecord);

            return(_table.ExecuteAsync(insertOrMergeOperation));
        }
    public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
    {
        string savedMessage = JsonSerializer.Serialize(message, new JsonSerializerOptions {
            WriteIndented = true
        });

        //logz.io/logstash fields can accept only 32k strings so request/response bodies are cut
        if (savedMessage.Length > _maxLogFieldLength)
        {
            savedMessage = savedMessage.Substring(0, _maxLogFieldLength);
        }

        //корреляционный идентификатор перезаписывается, если уже существует
        using (_log.BeginScopeWith((Logs.LogType, LogType.MessageBusMessage.ToString()),
                                   (Logs.MessageBusContextType, metadata.ContextType),
                                   (Logs.MessageBusSourceAddress, metadata.SourceAddress),
                                   (Logs.MessageBusDestinationAddress, metadata.DestinationAddress),
                                   (Logs.MessageBusMessageId, metadata.MessageId),
                                   (Logs.CorrelationId, metadata.CorrelationId),
                                   (Logs.MessageBusConversationId, metadata.ConversationId),
                                   (Logs.MessageBusMessage, savedMessage)))
        {
            _log.LogInformation("Message bus message has been stored.");
        }

        return(Task.CompletedTask);
    }
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            var auditEvent = new EventData(Guid.NewGuid(), TypeMetadataCache <T> .ShortName,
                                           true, Serialise(message), Serialise(metadata));

            return(_connection.AppendToStreamAsync(_auditStreamName, ExpectedVersion.Any, auditEvent));
        }
示例#4
0
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata)
            where T : class
        {
            var auditDocument = AuditDocument.Create(message, TypeMetadataCache <T> .ShortName, metadata);

            return(_collection.InsertOneAsync(auditDocument));
        }
示例#5
0
 public async Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
 {
     var auditEvent = new EventData(Guid.NewGuid(), TypeMetadataCache <T> .ShortName,
                                    true, Serialise(message), Serialise(metadata));
     await _connection.AppendToStreamAsync(StreamName, ExpectedVersion.Any, auditEvent)
     .ConfigureAwait(false);
 }
示例#6
0
        internal static AuditRecord Create <T>(T message, MessageAuditMetadata metadata, IPartitionKeyFormatter partitionKeyFormatter)
            where T : class
        {
            var record = new AuditRecord
            {
                RowKey             = $"{DateTime.MaxValue.Subtract(metadata.SentTime ?? DateTime.UtcNow).TotalMilliseconds}",
                ContextType        = metadata.ContextType,
                MessageId          = metadata.MessageId,
                ConversationId     = metadata.ConversationId,
                CorrelationId      = metadata.CorrelationId,
                InitiatorId        = metadata.InitiatorId,
                RequestId          = metadata.RequestId,
                SentTime           = metadata.SentTime,
                SourceAddress      = metadata.SourceAddress,
                InputAddress       = metadata.InputAddress,
                DestinationAddress = metadata.DestinationAddress,
                ResponseAddress    = metadata.ResponseAddress,
                FaultAddress       = metadata.FaultAddress,
                Headers            = JsonConvert.SerializeObject(metadata.Headers),
                Custom             = JsonConvert.SerializeObject(metadata.Custom),
                Message            = JsonConvert.SerializeObject(message),
                MessageType        = TypeMetadataCache <T> .ShortName
            };

            record.PartitionKey = SanitizePartitionKey(partitionKeyFormatter.Format <T>(record));

            return(record);
        }
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            // persist details of the call to durable logs DB
            Log.ForContext("MessageMetadata", metadata, true).Debug("Logged Message Metadata.");
            Log.ForContext("MessagePayload", message, true).Debug("Logged Message Payload.");

            return(Task.FromResult(0));
        }
示例#8
0
        async Task IMessageAuditStore.StoreMessage <T>(T message, MessageAuditMetadata metadata)
        {
            await using var dbContext = AuditContext;
            var auditRecord = AuditRecord.Create(message, TypeMetadataCache <T> .ShortName, metadata);

            await dbContext.Set <AuditRecord>().AddAsync(auditRecord).ConfigureAwait(false);

            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
        public virtual Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            Console.WriteLine($"{nameof(StoreMessage)} is called");

            var instance = JsonConvert.SerializeObject(message);

            Console.WriteLine(instance);

            return(Task.CompletedTask);
        }
示例#10
0
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            Console.WriteLine("message sent from {0} to {1}:", metadata.SourceAddress,
                              metadata.DestinationAddress);
            var parsed = JObject.FromObject(message);

            foreach (var pair in parsed)
            {
                Console.WriteLine("\t{0}: {1}", pair.Key, pair.Value);
            }
            return(Task.CompletedTask);
        }
        public virtual Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            if (message is IPastEvent pastEvent)
            {
                var streamId        = $"{pastEvent.Name}-{metadata.CorrelationId}";
                var jObject         = JsonConvert.SerializeObject(message);
                var jMetadataObject = JsonConvert.SerializeObject(metadata);
                var eventData       = new EventData(Guid.NewGuid(), pastEvent.Name, true, Encoding.UTF8.GetBytes(jObject),
                                                    Encoding.UTF8.GetBytes(jMetadataObject));

                return(_eventStoreConnection.AppendToStreamAsync(streamId, 1, eventData));
            }

            return(Task.CompletedTask);
        }
示例#12
0
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            Guard.ArgumentIsNotNull(message, nameof(message));
            Guard.ArgumentIsNotNull(metadata, nameof(metadata));

            string serializedMessage  = JsonConvert.SerializeObject(message);
            string serializedMetadata = JsonConvert.SerializeObject(metadata);

            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("Message", serializedMessage);
            parameters.Add("Metadata", serializedMetadata);
            parameters.Add("DateTime", DateTime.UtcNow);
            parameters.Add("ThreadId", Thread.CurrentThread.ManagedThreadId);

            return(ExecuteAsync("messagesaudit_create", parameters));
        }
示例#13
0
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            string savedMessage = JToken.Parse(JsonConvert.SerializeObject(message)).ToString(Formatting.Indented);

            //logz.io/logstash fields can accept only 32k strings so request/response bodies are cut
            if (savedMessage.Length > General.MaxLogFieldLength)
            {
                savedMessage = savedMessage.Substring(0, General.MaxLogFieldLength);
            }

            //CorrelationId being overwritten if exist
            _log.LogInformation("{LogType}{MessageBusContextType}{MessageBusDestinationAddress}{MessageBusSourceAddress}{CorrelationId}{MessageBusConversationId}{MessageBusMessage}",
                                LogTypes.MessageBusMessage.ToString(), metadata.ContextType, metadata.DestinationAddress, metadata.SourceAddress,
                                metadata.CorrelationId, metadata.ConversationId, savedMessage);

            return(Task.CompletedTask);
        }
示例#14
0
 internal static AuditRecord Create <T>(T message, string messageType, MessageAuditMetadata metadata)
     where T : class
 {
     return(new AuditRecord
     {
         ContextType = metadata.ContextType,
         MessageId = metadata.MessageId,
         ConversationId = metadata.ConversationId,
         CorrelationId = metadata.CorrelationId,
         InitiatorId = metadata.InitiatorId,
         RequestId = metadata.RequestId,
         SourceAddress = metadata.SourceAddress,
         DestinationAddress = metadata.DestinationAddress,
         ResponseAddress = metadata.ResponseAddress,
         FaultAddress = metadata.FaultAddress,
         Headers = metadata.Headers,
         Custom = metadata.Custom,
         Message = message,
         MessageType = messageType
     });
 }
        public async Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            var entry = new AuditEntry()
            {
                ContextType        = metadata.ContextType,
                ConversationId     = metadata.ConversationId,
                CorrelationId      = metadata.CorrelationId,
                Custom             = metadata.Custom,
                DestinationAddress = metadata.DestinationAddress,
                FaultAddress       = metadata.FaultAddress,
                Headers            = metadata.Headers,
                InitiatorId        = metadata.InitiatorId,
                MessageId          = metadata.MessageId,
                RequestId          = metadata.RequestId,
                ResponseAddress    = metadata.ResponseAddress,
                SourceAddress      = metadata.SourceAddress,
                //Styore message data
                MessageAsJson = JsonConvert.SerializeObject(message),
                MessageType   = message.GetType().ToString(),
                CreatedAt     = DateTime.Now
            };

            await _eventsStore.StoreAsync(entry);
        }
示例#16
0
 internal static AuditDocument Create <T>(T message, string messageType, MessageAuditMetadata metadata)
     where T : class
 {
     return(new AuditDocument
     {
         AuditId = NewId.NextGuid().ToString("N"),
         ContextType = metadata.ContextType,
         MessageId = metadata.MessageId.ToString(),
         ConversationId = metadata.ConversationId.ToString(),
         CorrelationId = metadata.CorrelationId.ToString(),
         InitiatorId = metadata.InitiatorId.ToString(),
         RequestId = metadata.RequestId.ToString(),
         SentTime = metadata.SentTime,
         SourceAddress = metadata.SourceAddress,
         DestinationAddress = metadata.DestinationAddress,
         ResponseAddress = metadata.ResponseAddress,
         InputAddress = metadata.InputAddress,
         FaultAddress = metadata.FaultAddress,
         Message = JsonConvert.SerializeObject(message),
         MessageType = messageType,
         Headers = AuditHeaders.FromDictionary(metadata.Headers),
         Custom = AuditHeaders.FromDictionary(metadata.Custom)
     });
 }
 public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
 {
     Console.WriteLine("audit");
     return(Task.CompletedTask);
 }
示例#18
0
 public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
 {
     _logger.LogInformation($"CorrelationId: {metadata.CorrelationId} => MessageAudit, Message: {message.Serialize()} , Metadata: {metadata.Serialize()}");
     return(Task.CompletedTask);
 }
示例#19
0
 public async Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
 {
     Console.WriteLine($"Auditing {metadata.MessageId}");
 }
        Task IMessageAuditStore.StoreMessage <T>(T message, MessageAuditMetadata metadata)
        {
            _audits.Add(new AuditRecord <T>(message, metadata));

            return(TaskUtil.Completed);
        }
示例#21
0
        public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            Log.Information($"[Audit] {metadata.ContextType} {typeof(T).FullName}: {JsonConvert.SerializeObject(message)} Metadata: {JsonConvert.SerializeObject(metadata, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })}");

            return(Task.CompletedTask);
        }
示例#22
0
        public async Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
        {
            await Console.Out.WriteLineAsync($"{_code} Payload: {JsonConvert.SerializeObject(message)}");

            await Console.Out.WriteLineAsync($"{_code} Metadata: {JsonConvert.SerializeObject(metadata)}");
        }
示例#23
0
 public Task StoreMessage <T>(T message, MessageAuditMetadata metadata) where T : class
 {
     return(_messageAuditStoreService.StoreMessage(message, metadata));
 }