diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9532d52..4374a0e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 5.7.0 +- Changed + - Updated IMessagePublisher and Dispatch contract to allow for setting more properties of the underlying ServiceBusMessage + ## 5.6.1 - fixed - Fixed an issue with dispatching messages when the Enabled flag is set to false. diff --git a/src/Ev.ServiceBus.Abstractions/Dispatch.cs b/src/Ev.ServiceBus.Abstractions/Dispatch.cs index bbf1dc4..5f88a23 100644 --- a/src/Ev.ServiceBus.Abstractions/Dispatch.cs +++ b/src/Ev.ServiceBus.Abstractions/Dispatch.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; namespace Ev.ServiceBus.Abstractions; @@ -11,21 +12,18 @@ public Dispatch(object payload) ApplicationProperties = new Dictionary(); } - public Dispatch(object payload, IDispatchContext context) - { - SessionId = context.SessionId; - CorrelationId = context.CorrelationId; - MessageId = context.MessageId; - DiagnosticId = context.DiagnosticId ?? Activity.Current?.Id; - ApplicationProperties = new Dictionary(context.ApplicationProperties); - Payload = payload; - } - public object Payload { get; } public string? SessionId { get; set; } public string? CorrelationId { get; set; } public string? MessageId { get; set; } public string? DiagnosticId { get; set; } + public string? PartitionKey { get; set; } + public string? TransactionPartitionKey { get; set; } + public string? ReplyToSessionId { get; set; } + public TimeSpan? TimeToLive { get; set; } + public string? Subject { get; set; } + public string? To { get; set; } + public string? ReplyTo { get; set; } + public DateTimeOffset? ScheduledEnqueueTime { get; set; } public IDictionary ApplicationProperties { get; } } - diff --git a/src/Ev.ServiceBus.Abstractions/IDispatchContext.cs b/src/Ev.ServiceBus.Abstractions/IDispatchContext.cs deleted file mode 100644 index 28057a3..0000000 --- a/src/Ev.ServiceBus.Abstractions/IDispatchContext.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace Ev.ServiceBus.Abstractions; - -public interface IDispatchContext -{ - public string? SessionId { get; set; } - public string? CorrelationId { get; set; } - public string? MessageId { get; set; } - /// - /// Unique identifier of call from producer to the queue or topic. Refer to W3C Trace-Context traceparent header for the format - /// - public string? DiagnosticId { get; set; } - IDictionary ApplicationProperties { get; } -} diff --git a/src/Ev.ServiceBus.Abstractions/IMessagePublisher.cs b/src/Ev.ServiceBus.Abstractions/IMessagePublisher.cs index 37f7aac..2fcc9be 100644 --- a/src/Ev.ServiceBus.Abstractions/IMessagePublisher.cs +++ b/src/Ev.ServiceBus.Abstractions/IMessagePublisher.cs @@ -25,5 +25,5 @@ public interface IMessagePublisher /// The object to send through Service Bus /// Configurator of message context /// A type of object that is registered within Ev.ServiceBus - void Publish(TMessagePayload messageDto, Action messageContextConfiguration); + void Publish(TMessagePayload messageDto, Action messageContextConfiguration); } \ No newline at end of file diff --git a/src/Ev.ServiceBus/Dispatch/DispatchContext.cs b/src/Ev.ServiceBus/Dispatch/DispatchContext.cs deleted file mode 100644 index 09e7071..0000000 --- a/src/Ev.ServiceBus/Dispatch/DispatchContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using Ev.ServiceBus.Abstractions; - -namespace Ev.ServiceBus.Dispatch; - -internal class DispatchContext : IDispatchContext -{ - public string? CorrelationId { get; set; } - public string? SessionId { get; set; } - public string? MessageId { get; set; } - /// - /// Unique identifier of call from producer to the queue or topic. Refer to W3C Trace-Context traceparent header for the format - /// - public string? DiagnosticId { get; set; } - public IDictionary ApplicationProperties { get; } = new Dictionary(); -} \ No newline at end of file diff --git a/src/Ev.ServiceBus/Dispatch/DispatchSender.cs b/src/Ev.ServiceBus/Dispatch/DispatchSender.cs index ed5c570..479c8c1 100644 --- a/src/Ev.ServiceBus/Dispatch/DispatchSender.cs +++ b/src/Ev.ServiceBus/Dispatch/DispatchSender.cs @@ -261,6 +261,26 @@ private ServiceBusMessage CreateMessage( } message.SessionId = dispatch.SessionId; + if (dispatch.PartitionKey is not null) + { + message.PartitionKey = dispatch.PartitionKey; + } + message.TransactionPartitionKey = dispatch.TransactionPartitionKey; + message.ReplyToSessionId = dispatch.ReplyToSessionId; + if (dispatch.TimeToLive is not null) + { + message.TimeToLive = dispatch.TimeToLive.Value; + } + if (dispatch.Subject is not null) + { + message.Subject = dispatch.Subject; + } + message.To = dispatch.To; + message.ReplyTo = dispatch.ReplyTo; + if (dispatch.ScheduledEnqueueTime is not null) + { + message.ScheduledEnqueueTime = dispatch.ScheduledEnqueueTime.Value; + } var originalCorrelationId = _messageMetadataAccessor.Metadata?.CorrelationId ?? Guid.NewGuid().ToString(); message.CorrelationId = dispatch.CorrelationId ?? originalCorrelationId; diff --git a/src/Ev.ServiceBus/Dispatch/MessageDispatcher.cs b/src/Ev.ServiceBus/Dispatch/MessageDispatcher.cs index 89552a3..60fe7c5 100644 --- a/src/Ev.ServiceBus/Dispatch/MessageDispatcher.cs +++ b/src/Ev.ServiceBus/Dispatch/MessageDispatcher.cs @@ -67,7 +67,7 @@ public void Publish(TMessagePayload messageDto, string sessionI /// public void Publish( TMessagePayload messageDto, - Action messageContextConfiguration) + Action messageContextConfiguration) { if (messageDto == null) { @@ -78,17 +78,9 @@ public void Publish( { throw new ArgumentNullException(nameof(messageContextConfiguration)); } + var dispatch = new Abstractions.Dispatch(messageDto); + messageContextConfiguration.Invoke(dispatch); - var context = new DispatchContext(); - - messageContextConfiguration.Invoke(context); - - _dispatchesToSend.Add(new Abstractions.Dispatch(messageDto, context) - { - SessionId = context.SessionId, - CorrelationId = context.CorrelationId, - MessageId = context.MessageId, - DiagnosticId = context.DiagnosticId ?? Activity.Current?.Id - }); + _dispatchesToSend.Add(dispatch); } } \ No newline at end of file