Repository navigation
[Mocha] Fix dispatch middleware running again when a stored message is delivered - #11016
Closed
tobias-tengler wants to merge 7 commits into
Closed
tobias-tengler wants to merge 7 commits into
tobias-tengler wants to merge 7 commits into
Conversation
This was referenced Nov 21, 2026
Merged
This was referenced Nov 21, 2026
Contributor
tobias-tengler
force-pushed
the
tte/mocha-single-pass-dispatch
branch
4 times, most recently
from
November 21, 2026 19:54
f232736 to
62e39b1
Compare
…s delivered A message that the outbox or a scheduler stored was delivered by running the dispatch pipeline a second time with SkipOutbox() and SkipScheduler() set. Bus middleware registered before the outbox therefore ran twice, and transport and endpoint middleware, such as the RabbitMQ routing key extractor, ran only at delivery. The pipeline now runs once, in the order instrumentation, transport and application middleware, serialization, scheduling, outbox, so everything is applied before the message is stored. The outbox processor and the scheduler workers send the stored envelope straight to the transport and record a failed send on their own span. UseOutboxCore() adds the outbox middleware as a fixed stage after scheduling, so anchors to it no longer depend on registration order. SkipScheduler() and SchedulingMiddlewareFeature are removed, and the scheduling and outbox middleware throw when a dispatch reaches them without an envelope.
…ion tests A test stores a published message in the outbox, delivers the stored envelope through DispatchInternalAsync and checks that the handler receives it while the outbox keeps the one stored message.
…messages The tests check that changes dispatch middleware makes before next end up in the stored message, that the message is serialized before middleware unwinds, that middleware can anchor to every built-in stage, that middleware anchored after serialization runs for a stored message, that a cancellation after the dispatch completes it, and that scheduling returns the requested time when middleware changes it after next.
…ey set by dispatch middleware Application middleware now runs before the RabbitMQ routing key extractor, so it can set the routing key header itself, but the extractor overwrote the header with the key extracted from the message. It now keeps a header that is already set, as the Azure Service Bus property middleware does. Tests cover that both extractors see a message that middleware replaced or changed, that middleware anchored after serialization reads the extracted values, and that Service Bus properties survive an envelope that was stored and read back.
…ransport The scheduler worker was the only code in the in-memory transport that used Mocha.Outbox, for SkipOutbox(). It sends stored envelopes directly now, so the project reference is removed. An application that got Mocha.Outbox only through the in-memory transport has to reference it itself.
…ed messages The middleware page shows the new dispatch order, says that middleware without an anchor runs before serialization, lists the keys of the built-in middleware and explains how anchors are resolved. The reliability, scheduling, observability and transport pages say that dispatch middleware runs when a message is stored and that the outbox processor and the scheduler send the stored envelope directly. The skip-the-outbox section shows a middleware anchored before OutboxDispatchMiddlewares.Outbox. The dispatch registration sample no longer calls an AddMessageBus overload that does not exist.
The migration guide covers the removal of SkipScheduler(), the in-memory transport no longer referencing Mocha.Outbox, stored messages bypassing middleware during delivery, including rows written by 16.7, and the new position of middleware registered without an anchor.
tobias-tengler
force-pushed
the
tte/mocha-single-pass-dispatch
branch
from
November 23, 2026 13:31
8b1fc2c to
09ca87a
Compare
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.
UseDispatchwithout an anchor runs before serialization.outbox sendandscheduler sendspans record a failed send.UseOutboxCore()adds the outbox middleware as a fixed stage after scheduling, withOutboxDispatchMiddlewares.Outboxas its anchor, and registers once when called twice.SkipScheduler()andSchedulingMiddlewareFeatureare removed.Mocha.Transport.InMemoryno longer referencesMocha.Outbox.