Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions src/Ev.ServiceBus.Abstractions/Dispatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Ev.ServiceBus.Abstractions;
Expand All @@ -11,21 +12,18 @@ public Dispatch(object payload)
ApplicationProperties = new Dictionary<string, object>();
}

public Dispatch(object payload, IDispatchContext context)
{
SessionId = context.SessionId;
CorrelationId = context.CorrelationId;
MessageId = context.MessageId;
DiagnosticId = context.DiagnosticId ?? Activity.Current?.Id;
ApplicationProperties = new Dictionary<string, object>(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<string,object> ApplicationProperties { get; }
}

15 changes: 0 additions & 15 deletions src/Ev.ServiceBus.Abstractions/IDispatchContext.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Ev.ServiceBus.Abstractions/IMessagePublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface IMessagePublisher
/// <param name="messageDto">The object to send through Service Bus</param>
/// <param name="messageContextConfiguration">Configurator of message context</param>
/// <typeparam name="TMessagePayload">A type of object that is registered within Ev.ServiceBus</typeparam>
void Publish<TMessagePayload>(TMessagePayload messageDto, Action<IDispatchContext> messageContextConfiguration);
void Publish<TMessagePayload>(TMessagePayload messageDto, Action<Dispatch> messageContextConfiguration);
}
16 changes: 0 additions & 16 deletions src/Ev.ServiceBus/Dispatch/DispatchContext.cs

This file was deleted.

20 changes: 20 additions & 0 deletions src/Ev.ServiceBus/Dispatch/DispatchSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@

private class MessagesPerResource
{
public MessageToSend[] Messages { get; set; }

Check warning on line 204 in src/Ev.ServiceBus/Dispatch/DispatchSender.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Messages' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public ClientType ClientType { get; set; }
public string ResourceId { get; set; }

Check warning on line 206 in src/Ev.ServiceBus/Dispatch/DispatchSender.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ResourceId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public IMessageSender Sender { get; set; }

Check warning on line 207 in src/Ev.ServiceBus/Dispatch/DispatchSender.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Sender' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

private class MessageToSend
Expand Down Expand Up @@ -261,6 +261,26 @@
}

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;
Expand Down
16 changes: 4 additions & 12 deletions src/Ev.ServiceBus/Dispatch/MessageDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Publish<TMessagePayload>(TMessagePayload messageDto, string sessionI
/// <inheritdoc />
public void Publish<TMessagePayload>(
TMessagePayload messageDto,
Action<IDispatchContext> messageContextConfiguration)
Action<Abstractions.Dispatch> messageContextConfiguration)
{
if (messageDto == null)
{
Expand All @@ -78,17 +78,9 @@ public void Publish<TMessagePayload>(
{
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);
}
}
Loading