Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that DeadLetters published by DistributedPubSubMediator contain full context of topic #6209

Merged
merged 1 commit into from
Oct 24, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ public DistributedPubSubMediator(DistributedPubSubSettings settings)
new Router(_settings.RoutingLogic, routees.ToArray()).Route(
Internal.Utils.WrapIfNeeded(send.Message), Sender);
else
IgnoreOrSendToDeadLetters(send.Message);
IgnoreOrSendToDeadLetters(send);
});
Receive<SendToAll>(sendToAll =>
{
PublishMessage(sendToAll.Path, sendToAll.Message, sendToAll.ExcludeSelf);
PublishMessage(sendToAll.Path, sendToAll, sendToAll.ExcludeSelf);
});
Receive<Publish>(publish =>
{
string path = Internal.Utils.MakeKey(Self.Path / Internal.Utils.EncodeName(publish.Topic));
if (publish.SendOneMessageToEachGroup)
PublishToEachGroup(path, publish.Message);
PublishToEachGroup(path, publish);
else
PublishMessage(path, publish.Message);
PublishMessage(path, publish);
});
Receive<Put>(put =>
{
Expand Down Expand Up @@ -500,7 +500,7 @@ private void IgnoreOrSendToDeadLetters(object message)
Context.System.DeadLetters.Tell(new DeadLetter(message, Sender, Context.Self));
}

private void PublishMessage(string path, object message, bool allButSelf = false)
private void PublishMessage(string path, IWrappedMessage publish, bool allButSelf = false)
Copy link
Member Author

Choose a reason for hiding this comment

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

Rather than send just the object Message to these methods, send the full IWrappedMessage payload which we'll pass directly to the IgnoreOrSendToDeadLetters method - as that wrapper message includes all of the useful debugging context a developer might need.

{
IEnumerable<IActorRef> Refs()
{
Expand All @@ -521,24 +521,24 @@ IEnumerable<IActorRef> Refs()
foreach (var r in Refs())
{
if (r == null) continue;
r.Forward(message);
r.Forward(publish.Message);
counter++;
}

if (counter == 0) IgnoreOrSendToDeadLetters(message);
if (counter == 0) IgnoreOrSendToDeadLetters(publish);
}

private void PublishToEachGroup(string path, object message)
private void PublishToEachGroup(string path, Publish publish)
{
var prefix = path + "/";
var lastKey = path + "0"; // '0' is the next char of '/'

var groups = ExtractGroups(prefix, lastKey).GroupBy(kv => kv.Key).ToList();
var wrappedMessage = new SendToOneSubscriber(message);
var wrappedMessage = new SendToOneSubscriber(publish.Message);
Copy link
Member Author

Choose a reason for hiding this comment

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

Forward only the payload to the subscriber still, preserving the same behavior as before.


if (groups.Count == 0)
{
IgnoreOrSendToDeadLetters(message);
IgnoreOrSendToDeadLetters(publish);
Copy link
Member Author

Choose a reason for hiding this comment

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

Send the full, debuggable payload to DeadLetters

}
else
{
Expand Down