Commit 4a5da908 authored by Dmitry's avatar Dmitry Committed by Savorboard

Write publish message store (#380)

* made possible updating message before storing to db

made updating message Content possible on WritePublishMessageStoreBefore event

* added TracingHeaders to BrokerStoreEventData model
parent 47b1dc5c
...@@ -68,7 +68,12 @@ namespace DotNetCore.CAP.Abstractions ...@@ -68,7 +68,12 @@ namespace DotNetCore.CAP.Abstractions
try try
{ {
operationId = s_diagnosticListener.WritePublishMessageStoreBefore(message); var tracingResult = TracingBefore(message.Name, message.Content);
operationId = tracingResult.Item1;
message.Content = tracingResult.Item2 != null
? Helper.AddTracingHeaderProperty(message.Content, tracingResult.Item2)
: message.Content;
if (Transaction.Value?.DbTransaction == null) if (Transaction.Value?.DbTransaction == null)
{ {
...@@ -100,6 +105,21 @@ namespace DotNetCore.CAP.Abstractions ...@@ -100,6 +105,21 @@ namespace DotNetCore.CAP.Abstractions
throw; throw;
} }
} }
private (Guid, TracingHeaders) TracingBefore(string topic, string values)
{
Guid operationId = Guid.NewGuid();
var eventData = new BrokerStoreEventData(
operationId,
"",
topic,
values);
s_diagnosticListener.WritePublishMessageStoreBefore(eventData);
return (operationId, eventData.Headers);
}
protected abstract Task ExecuteAsync(CapPublishedMessage message, protected abstract Task ExecuteAsync(CapPublishedMessage message,
ICapTransaction transaction = null, ICapTransaction transaction = null,
......
...@@ -38,26 +38,13 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -38,26 +38,13 @@ namespace DotNetCore.CAP.Diagnostics
//============================================================================ //============================================================================
//==================== Before publish store message ==================== //==================== Before publish store message ====================
//============================================================================ //============================================================================
public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this, public static void WritePublishMessageStoreBefore(this DiagnosticListener @this, BrokerStoreEventData eventData)
CapPublishedMessage message,
[CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapBeforePublishMessageStore)) if (@this.IsEnabled(CapBeforePublishMessageStore))
{ {
var operationId = Guid.NewGuid(); eventData.Headers = new TracingHeaders();
@this.Write(CapBeforePublishMessageStore, eventData);
@this.Write(CapBeforePublishMessageStore, new
{
OperationId = operationId,
Operation = operation,
MessageName = message.Name,
MessageContent = message.Content
});
return operationId;
} }
return Guid.Empty;
} }
public static void WritePublishMessageStoreAfter(this DiagnosticListener @this, public static void WritePublishMessageStoreAfter(this DiagnosticListener @this,
......
using System;
namespace DotNetCore.CAP.Diagnostics
{
public class BrokerStoreEventData : EventData
{
public BrokerStoreEventData(
Guid operationId,
string operation,
string messageName,
string messageContent) : base(operationId, operation)
{
MessageName = messageName;
MessageContent = messageContent;
}
public string MessageName { get; set; }
public string MessageContent { get; set; }
public TracingHeaders Headers { get; set; }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment