Introduce routing conditions for inbound message processing#9869
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a condition-based routing model for inbound message processing. Instead of routing solely by resolved MessageType, inbound routes now carry a RouteCondition that is evaluated against the receive context (headers + resolved type), enabling scenarios like saga reply routing via headers on a shared reply endpoint.
Changes:
- Add
RouteConditionabstraction (and built-in implementations) and persist it onInboundRoutewith diagnostic descriptions. - Update
RoutingMiddlewareto select consumers by evaluating each route’s condition (supports non-type routing such as header-based selection). - Update saga reply routing to gate selection on the saga-id header (and optionally message type) and expand test coverage around reply routing behavior.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Mocha/test/Mocha.Tests/Middlewares/Receive/RoutingMiddlewareTests.cs | Updates routing middleware tests to validate condition-based selection and deduping. |
| src/Mocha/test/Mocha.Tests/MessageTypes/InboundRouteTests.cs | Adds tests for InboundRoute.Initialize deriving non-null/default conditions. |
| src/Mocha/test/Mocha.Tests/MessageTypes/Conditions/RouteConditionTests.cs | Adds unit tests for the condition types (MessageType, HeaderPresent, And, NoMatch). |
| src/Mocha/test/Mocha.Sagas.Tests/SagaRouteConditionTests.cs | Verifies saga-derived reply conditions (saga-id gating and typed reply composition). |
| src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs | Enables request/response saga test and adds integration coverage for saga reply routing scenarios. |
| src/Mocha/src/Mocha/Sagas/SagaEventListener.cs | Applies explicit reply conditions to saga reply routes to avoid RPC contamination. |
| src/Mocha/src/Mocha/Sagas/Saga.cs | Documents routing replies to the shared reply endpoint and correlating via saga header. |
| src/Mocha/src/Mocha/Middlewares/Receive/RoutingMiddleware.cs | Switches routing logic to evaluate InboundRoute.Condition rather than manual type comparisons. |
| src/Mocha/src/Mocha/Middlewares/DefaultMessageBus.cs | Clarifies correlation-id propagation semantics (don’t inherit per-hop correlation). |
| src/Mocha/src/Mocha/MessageTypes/InboundRoute.cs | Adds Condition property, derives default condition during initialize, and includes it in route descriptions. |
| src/Mocha/src/Mocha/MessageTypes/Descriptors/InboundRouteDescriptor.cs | Adds descriptor support for setting a custom route condition. |
| src/Mocha/src/Mocha/MessageTypes/Descriptors/IInboundRouteDescriptor.cs | Extends public descriptor interface with Condition(RouteCondition condition). |
| src/Mocha/src/Mocha/MessageTypes/Configurations/InboundRouteConfiguration.cs | Adds Condition configuration hook for inbound routes. |
| src/Mocha/src/Mocha/MessageTypes/Conditions/RouteCondition.cs | Introduces the base RouteCondition abstraction. |
| src/Mocha/src/Mocha/MessageTypes/Conditions/NoMatchCondition.cs | Adds a never-match condition for inert/shared reply routes. |
| src/Mocha/src/Mocha/MessageTypes/Conditions/MessageTypeCondition.cs | Adds condition for matching by message type (with optional “match when type is missing”). |
| src/Mocha/src/Mocha/MessageTypes/Conditions/HeaderPresentCondition.cs | Adds condition for matching based on header presence. |
| src/Mocha/src/Mocha/MessageTypes/Conditions/AndCondition.cs | Adds composite condition that matches only when all child conditions match. |
| src/Mocha/src/Mocha/Descriptions/RouteConditionDescription.cs | Adds structured descriptions for conditions (diagnostics/visualization). |
| src/Mocha/src/Mocha/Descriptions/InboundRouteDescription.cs | Extends route description to include condition description. |
| src/Mocha/src/Mocha/Consumers/Extensions/ConsumeContextExtensions.cs | Allows creating reply options even when correlation id is absent (supports saga-header correlation). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 16, 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.