Skip to content

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented May 15, 2025

Changes

Fix #7626: Using DeadLetterWithNoSubscribers to clearly indicate when here are no subscribers

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

…ss to clearly indicate no subscriber case in dead letter messages

- Made DeadLetterWithNoSubscribers internal (class already existed)
- Added test to verify dead letter messages are sent when no subscribers exist
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Detailed my changes

Copy link
Member Author

Choose a reason for hiding this comment

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

Trying out AMP code and this is the agent rules file for that

var testMessage = "test-message";

// act - publish to a topic that no one is subscribed to
await EventFilter.Info(contains: "DeadLetterWithNoSubscribers")
Copy link
Member Author

Choose a reason for hiding this comment

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

Validates that we get a more descriptive log message indicating that this message got DeadLetter'd because there were no subscribers

// Use the specialized DeadLetterWithNoSubscribers class to clearly indicate
// that the message was not delivered because there were no subscribers,
// not because the mediator itself is dead.
var deadLetter = new DeadLetterWithNoSubscribers(message, Sender, Context.Self);
Copy link
Member Author

Choose a reason for hiding this comment

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

Uses the new custom dead letter type when we're routing messages to dead letters

/// DeadLetters because there were no subscribers for the topic in DistributedPubSub,
/// NOT because the mediator itself is dead.
/// </summary>
internal sealed class DeadLetterWithNoSubscribers : AllDeadLetters
Copy link
Member Author

Choose a reason for hiding this comment

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

internal type, so no changes in public API

Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Mentioned updates

if (_settings.SendToDeadLettersWhenNoSubscribers)
Context.System.DeadLetters.Tell(new DeadLetter(message, Sender, Context.Self));
{
var topic = message switch
Copy link
Member Author

Choose a reason for hiding this comment

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

Tries to extract the topic from the message so we can be as accurate as possible during the DeadLetter logging

/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return $"DeadLetterWithNoSubscribers from {Sender} to {Recipient}: <{Message}> - No subscribers found for topic {Topic}";
Copy link
Member Author

Choose a reason for hiding this comment

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

Topic should never actually be null - but that may change in the future if we start using IgnoreOrSendToDeadLetters for anything other than Send and Publish

@Aaronontheweb Aaronontheweb marked this pull request as ready for review May 15, 2025 16:26
Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

LGTM

This was referenced Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DistributedPubSub: DeadLetter logging when no subscribers looks identical to the Mediator being dead

2 participants