Add retry/redeliver to mocha#9494
Merged
PascalSenn merged 15 commits intomainfrom Apr 9, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces first-class immediate retry (consumer pipeline) and delayed redelivery (receive pipeline) to Mocha, including configuration APIs, middleware implementations, documentation updates, and in-memory transport test coverage.
Changes:
- Add Polly-based consumer retry middleware with configurable backoff, intervals, and exception filtering.
- Add receive-pipeline redelivery middleware that schedules failed messages for later delivery and tracks redelivery count via headers.
- Update reliability documentation, demo apps, and add in-memory transport tests for retry/redelivery.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/docs/mocha/v1/reliability.md | Documents retry/redelivery concepts, configuration, and pipeline ordering. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/RetryTests.cs | Adds in-memory tests for retry behavior, overrides, and retry state exposure. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/RedeliveryTests.cs | Adds in-memory tests for redelivery scheduling, defaults, and overrides. |
| src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/RedeliveryOptions.cs | Adds redelivery options model + exception filtering rules. |
| src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/RedeliveryFeature.cs | Adds feature wrapper to expose/hold redelivery configuration. |
| src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/RedeliveryConfigurationExtensions.cs | Adds .AddRedelivery() builder/descriptor extension methods. |
| src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/ReceiveRedeliveryMiddleware.cs | Implements delayed redelivery (scheduling + header tracking + ignore rules). |
| src/Mocha/src/Mocha/Middlewares/Receive/ReceiveMiddlewares.cs | Registers redelivery middleware configuration. |
| src/Mocha/src/Mocha/Middlewares/Extensions/MiddlewareConfigurationExtensions.cs | Prevents duplicate consumer middleware registration by key during prepend. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryState.cs | Introduces retry state feature exposed to handlers. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryOptions.cs | Adds retry options model + exception filtering rules. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryFeature.cs | Adds feature wrapper to expose/hold retry configuration. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryConfigurationExtensions.cs | Adds .AddRetry() builder/descriptor extension methods. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryBackoffType.cs | Adds retry backoff type enum. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/ExceptionRuleMatcher.cs | Implements “most-specific-type-wins” exception ignore matching. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/ExceptionRule.cs | Adds internal exception rule representation. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/ExceptionPolicyBuilder.cs | Adds fluent On<T>().Ignore() builder. |
| src/Mocha/src/Mocha/Middlewares/Consume/Retry/ConsumerRetryMiddleware.cs | Implements Polly-based retry middleware and exposes RetryState. |
| src/Mocha/src/Mocha/Middlewares/Consume/ConsumerMiddlewares.cs | Registers retry middleware configuration. |
| src/Mocha/src/Mocha/Headers/MessageHeaders.cs | Adds delayed-retry-count header key under MessageHeaders.Retry. |
| src/Mocha/src/Mocha/Extensions/IMessageBusHostBuilderExtensions.cs | Adds host-builder overloads enabling per-consumer configuration at registration. |
| src/Mocha/src/Demo/Demo.Shipping/Program.cs | Enables retry + redelivery in demo shipping service. |
| src/Mocha/src/Demo/Demo.Catalog/Program.cs | Enables retry + redelivery in demo catalog service. |
| src/Mocha/src/Demo/Demo.Billing/Program.cs | Enables retry + redelivery in demo billing service. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9494 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…re and add tests for RetryExecutor
…umer resilience methods in middleware
…dOnlyList for consistency and improved performance
…improve documentation for clarity
…ng and enhance exception handling; add new RedeliveryAction and RedeliveryDecision types for clarity and maintainability
…rt cosmetic changes The RetryExecutor used a custom DelayAsync method with TaskCompletionSource that caused thread pool starvation hangs when tests ran in parallel. Replaced with the built-in Task.Delay(TimeSpan, TimeProvider, CancellationToken) overload. Rewrote two FakeTimeProvider-dependent tests to avoid unawaited async operations that deadlock under thread pool contention. Also reverts unintentional em-dash removal in examples, docs, and unrelated test files.
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.