Skip to content

Use explicit message settlement via ServiceBusMessageActions#43

Open
andreasohlund wants to merge 49 commits intomainfrom
explicit-message-settlement
Open

Use explicit message settlement via ServiceBusMessageActions#43
andreasohlund wants to merge 49 commits intomainfrom
explicit-message-settlement

Conversation

@andreasohlund
Copy link
Member

@andreasohlund andreasohlund commented Mar 19, 2026

This uses message actions to explicitly control message settlement, including the ability to DLQ messages and perform other advanced operations that are only available via the actions.

This PR also:

  • Removes support for the ASB transport legacy body format
  • Require message ID to be set, similar to the transport
  • Align upconversion of message properties to headers with the ASB transport
  • Support explicit DLQ requests via recoverability action
  • DLQ messages when OnError fails with non-transient exception

@andreasohlund
Copy link
Member Author

@danielmarbach ready for a initial review, some todos left in code for us to discuss

@andreasohlund andreasohlund changed the title Use explicit message settlement Use explicit message settlement via ServiceBusMessageActions Mar 22, 2026
@andreasohlund
Copy link
Member Author

@danielmarbach addressed your comment, there are a few things that needs to be discussed, left those as TODO's in the code

@andreasohlund andreasohlund marked this pull request as ready for review March 24, 2026 12:57
@andreasohlund
Copy link
Member Author

@danielmarbach ready for final review

{
logger.LogError(exception, "Message dead lettered due to exception");

return messageActions.DeadLetterMessageAsync(message,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the transport, we wrap things we more try catch inside and log statements. Worth doing something similar? Doesn't have to be an extension method thught

https://github.com/Particular/NServiceBus.Transport.AzureServiceBus/blob/e844c7cde49682c0010f309ecfc9eabd74dcf5f8/src/Transport/Receiving/ProcessMessageEventArgsExtensions.cs#L72


public class DeadLetterMessage(string deadLetterReason, string deadLetterErrorDescription, Dictionary<string, object>? propertiesToModify = null) : RecoverabilityAction
{
public DeadLetterMessage(Exception exception) : this($"{exception.GetType().FullName!} - {exception.Message}", exception.StackTrace ?? exception.ToString(), null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand there are restrictions on how much data we can pass. So I wonder if we should do the following:

DeadLetterReason = ex.GetType().FullName
DeadLetterErrorDescription = first 1024-2048 chars of ex.Message

and then set the regular NServiceBus Exception headers like core would do because then things are already in the right shape and if that fails just the reason and the description and if that fails nothing else. Then in the best case you always get some extra useful information but in the case we have a message that is close to the message size restrictions we can still dead-letter things properly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should we allow modifying the source or should we keep that auto assigned by the service?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants