Skip to content

Add retry/redeliver to mocha#9494

Merged
PascalSenn merged 15 commits intomainfrom
pse/retry-policies-for-mocha
Apr 9, 2026
Merged

Add retry/redeliver to mocha#9494
PascalSenn merged 15 commits intomainfrom
pse/retry-policies-for-mocha

Conversation

@PascalSenn
Copy link
Copy Markdown
Member

@PascalSenn PascalSenn commented Mar 31, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 31, 2026 19:34
@github-actions github-actions Bot added the 📚 documentation This issue is about working on our documentation. label Mar 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/ReceiveRedeliveryMiddleware.cs Outdated
Comment thread src/Mocha/src/Mocha/Middlewares/Consume/Retry/ConsumerRetryMiddleware.cs Outdated
Comment thread src/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryState.cs Outdated
Comment thread website/src/docs/mocha/v1/reliability.md
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (f107863) to head (c576caf).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #9494   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

PascalSenn and others added 11 commits April 7, 2026 23:25
…dOnlyList for consistency and improved performance
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ mocha

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants