Browse Source

Add support for custom message id. #668

master
Savorboard 4 years ago
parent
commit
623966fb91
1 changed files with 10 additions and 9 deletions
  1. +10
    -9
      src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs

+ 10
- 9
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs View File

@@ -63,21 +63,22 @@ namespace DotNetCore.CAP.Internal
throw new ArgumentNullException(nameof(name));
}

if (headers == null)
headers ??= new Dictionary<string, string>();

if (!headers.ContainsKey(Headers.MessageId))
{
headers = new Dictionary<string, string>();
var messageId = SnowflakeId.Default().NextId().ToString();
headers.Add(Headers.MessageId, messageId);
}

var messageId = SnowflakeId.Default().NextId().ToString();
headers.Add(Headers.MessageId, messageId);
headers.Add(Headers.MessageName, name);
headers.Add(Headers.Type, typeof(T).Name);
headers.Add(Headers.SentTime, DateTimeOffset.Now.ToString());
if (!headers.ContainsKey(Headers.CorrelationId))
{
headers.Add(Headers.CorrelationId, messageId);
headers.Add(Headers.CorrelationId, headers[Headers.MessageId]);
headers.Add(Headers.CorrelationSequence, 0.ToString());
}
headers.Add(Headers.MessageName, name);
headers.Add(Headers.Type, typeof(T).Name);
headers.Add(Headers.SentTime, DateTimeOffset.Now.ToString());

var message = new Message(headers, value);



Loading…
Cancel
Save