Skip to content

GH-6127 The topics of a ListenToKafkaTopics group get Kafka retry tiers - #6134

Open
lahma wants to merge 1 commit into
JasperFx:mainfrom
lahma:gh-6127-kafka-topic-group-retry-tiers
Open

lahma wants to merge 1 commit into
JasperFx:mainfrom
lahma:gh-6127-kafka-topic-group-retry-tiers

Conversation

@lahma

@lahma lahma commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

MoveToKafkaRetryTopic(...) registered retry-tier listeners only for the topics in KafkaTransport.Topics, and a ListenToKafkaTopics(...) group lives in TopicGroups, so its topics got no tiers. The continuation still applied to the group's listener: it produced the failure to <topic>.retry.<delay> and committed the source offset, and on a cluster that auto-creates topics nothing read the record again.

Change

  • RetryTierSourceTopics takes the topics of every listening KafkaTopicGroup as sources too. A topic listened to alone and in a group gets its tiers once.
  • Each tier inherits the native dead letter setting of the listener that reads its source topic, the group for a group's topic. The setting is looked up with TryFind, not the Topics indexer, which would register an endpoint for each topic of the group.
  • The guide says that a group's topics get tiers.

Tests (kafka_retry_topics_for_topic_groups_6127.cs)

  • Two unit tests of RetryTierSourceTopics: a group's topics are sources, and a topic in both a group and a listener of its own is listed once.
  • Three tests against the compose broker, modelled on kafka_retry_topics:
    • each topic of the group has its tier listeners, with the group's dead letter setting;
    • a transient failure on a group topic is retried through the tiers and succeeds;
    • a permanent failure goes through every tier and lands in the dead letter topic.
  • All five fail without the fix. With it, they pass beside kafka_retry_topics, kafka_retry_topics_on_a_named_broker_6064, multi_topic_listening and the Kafka: JsonOnlyMapper overwrites the record key on copies, and topics named *.retry.* get no retry tiers #5772 tier tests (14 of 14).

Fixes #6127

🤖 Generated with Claude Code

…etry tiers

RetryTierSourceTopics took the source topics from KafkaTransport.Topics
only, and a ListenToKafkaTopics(...) group lives in TopicGroups, so its
topics got no retry-tier listeners. MoveToKafkaRetryTopic still applied to
the group's listener: a failure was produced to {topic}.retry.{delay} and
the source offset committed, and on a cluster that auto-creates topics
nothing ever read the record again.

The topics of every listening group are now tier sources too, each with
the group's native dead letter setting. The setting is looked up without
the Topics indexer, which would register an endpoint for each topic of the
group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 09:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Retry endpoints can apply the wrong dead-letter policy across listeners sharing a topic and lose group-bound sticky handlers, causing misrouted failures or handler-resolution exceptions.

2 open issues
What changed in this PR

Extends Wolverine’s Kafka retry tiers to ListenToKafkaTopics(...) groups, addressing GH-6127’s unconsumed retry messages.

Changes:

  • Includes group topics as retry sources, deduplicating overlapping subscriptions.
  • Copies source-listener native dead-letter settings to retry tiers.
  • Adds regression tests and documents group support.
File Description
src/​Transports/​Kafka/​Wolverine.Kafka/​Internals/​KafkaTransport.cs Includes group topics and resolves source-listener dead-letter settings.
src/​Transports/​Kafka/​Wolverine.Kafka.Tests/​kafka_retry_topics_for_topic_groups_6127.cs Tests source discovery, deduplication, retries, and dead-letter delivery.
docs/​guide/​messaging/​transports/​kafka.md Clarifies that group topics receive retry tiers.

Review effort: Balanced

Comment on lines +389 to +391
return Topics.TryFind(topicName, out var topic) && topic.IsListener
? topic
: TopicGroups.First(g => g.IsListener && g.TopicNames.Contains(topicName));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Each tier is one endpoint per topic and delay, so it carries one dead letter setting. That was already so before this change: a topic has one tier set, however many listeners read it. When a topic is read both by a listener of its own and by a group, the tiers take the topic's own listener's setting, which is what Topics[source] gave before.

Reading one topic through two listeners on the same node, with different dead letter settings, is a configuration I'd rather leave to the maintainers: either refuse it at startup, or carry the originating listener's policy through the retry headers. Neither is needed to get a group's failures retried at all, so I've kept this PR to that.

var listened = Topics
.Where(t => t.IsListener && t.RetryTierDelay == null)
.Select(t => t.TopicName)
.Concat(TopicGroups.Where(g => g.IsListener).SelectMany(g => g.TopicNames))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't specific to groups. A tier topic is a separate KafkaTopic endpoint, and nothing copies the source listener's StickyHandlers to it. So ListenToKafkaTopic("orders").AddStickyHandler(...) with MoveToKafkaRetryTopic(...) already resolves no handler on orders.retry.<delay> when every chain for the message type is sticky. That is true on main today, before this PR.

Before this PR a group's failure was never retried at all. A group now behaves exactly as a single topic does. Binding the source's sticky handlers to its tiers would fix both cases. It is a separate change, and I'd suggest a follow-up issue for it rather than widening this one.

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.

Kafka: MoveToKafkaRetryTopic(...) on a ListenToKafkaTopics(...) listener moves failed messages to a retry topic nobody consumes

2 participants