Skip to content

Introduce routing conditions for inbound message processing#9869

Merged
PascalSenn merged 6 commits into
mainfrom
feat/introduce-route-conditons
Jun 7, 2026
Merged

Introduce routing conditions for inbound message processing#9869
PascalSenn merged 6 commits into
mainfrom
feat/introduce-route-conditons

Conversation

@PascalSenn

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 7, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 RouteCondition abstraction (and built-in implementations) and persist it on InboundRoute with diagnostic descriptions.
  • Update RoutingMiddleware to 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.

Comment thread src/Mocha/test/Mocha.Tests/MessageTypes/InboundRouteTests.cs
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
PascalSenn and others added 5 commits June 7, 2026 21:57
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>

@PascalSenn PascalSenn left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants