diff --git a/src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs b/src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs index 01141cd..c238bf8 100644 --- a/src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs +++ b/src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs @@ -63,21 +63,22 @@ namespace DotNetCore.CAP.Internal throw new ArgumentNullException(nameof(name)); } - if (headers == null) + headers ??= new Dictionary(); + + if (!headers.ContainsKey(Headers.MessageId)) { - headers = new Dictionary(); + 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);