Kaynağa Gözat

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 yıl önce
committed by Savorboard
ebeveyn
işleme
4a5da9085c
3 değiştirilmiş dosya ile 46 ekleme ve 17 silme
  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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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; }
}
}

Yükleniyor…
İptal
Kaydet