Sfoglia il codice sorgente

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
master
Dmitry 5 anni fa
committed by Savorboard
parent
commit
4a5da9085c
3 ha cambiato i file con 46 aggiunte e 17 eliminazioni
  1. +21
    -1
      src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
  2. +3
    -16
      src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs
  3. +22
    -0
      src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs

+ 21
- 1
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs Vedi File

@@ -68,7 +68,12 @@ namespace DotNetCore.CAP.Abstractions

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)
{
@@ -100,6 +105,21 @@ namespace DotNetCore.CAP.Abstractions
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,
ICapTransaction transaction = null,


+ 3
- 16
src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs Vedi File

@@ -38,26 +38,13 @@ namespace DotNetCore.CAP.Diagnostics
//============================================================================
//==================== Before publish store message ====================
//============================================================================
public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this,
CapPublishedMessage message,
[CallerMemberName] string operation = "")
public static void WritePublishMessageStoreBefore(this DiagnosticListener @this, BrokerStoreEventData eventData)
{
if (@this.IsEnabled(CapBeforePublishMessageStore))
{
var operationId = Guid.NewGuid();

@this.Write(CapBeforePublishMessageStore, new
{
OperationId = operationId,
Operation = operation,
MessageName = message.Name,
MessageContent = message.Content
});

return operationId;
eventData.Headers = new TracingHeaders();
@this.Write(CapBeforePublishMessageStore, eventData);
}

return Guid.Empty;
}

public static void WritePublishMessageStoreAfter(this DiagnosticListener @this,


+ 22
- 0
src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs Vedi File

@@ -0,0 +1,22 @@
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; }
}
}

Caricamento…
Annulla
Salva