Skip to content

[Mocha] Signal the outbox processor only when a transaction wrote an outbox message - #11110

Open
PascalSenn wants to merge 5 commits into
mainfrom
pse/mocha-outbox-split-6-signal-on-write
Open

PascalSenn wants to merge 5 commits into
mainfrom
pse/mocha-outbox-split-6-signal-on-write

Conversation

@PascalSenn

@PascalSenn PascalSenn commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Split out of #11017. Builds on #11108 and #11109, merge after both. The branch contains a merge of the two, so the diff against main includes them.

Own commits:

Changes:

  • A commit wakes the outbox processor only when its transaction wrote an outbox message.
  • OutboxSaveChangesInterceptor is removed. A save no longer wakes the processor.
  • An OutboxMessage entity that is added through the change tracker is found when the processor next checks the database.

tobias-tengler and others added 5 commits November 29, 2026 13:41
…t signaled about

An idle outbox processor waited for its signal without a timeout. A row committed without a signal, for example in a transaction that is committed outside EF Core or by another process, stayed in the outbox until something else woke the processor. The processor now also wakes after PostgresOutboxOptions.PollingInterval, ten seconds by default, and an interval that is not positive is rejected. It logs that it is sleeping only when it waits for a message that is due before the next check.
…Contexts use it

UsePostgresOutbox() registered the processor and its worker as plain singletons, so with two contexts the host ran only the processor of the context registered last and the rows of the other context were never sent. All processors also waited on one IOutboxSignal.

Each context now gets its own processor, registered as a keyed singleton with the context type as key, its own worker and its own IOutboxSignal, registered with the same key. The outbox interceptors read the signal from the context they are called for, so a save or commit signals only the processor of that context. Calling UsePostgresOutbox() or UseOutboxCore() again for the same context registers nothing twice and still applies the configure delegate. IMessageBus publishes keep using the outbox of the first context, and the exception for a missing transaction now says so.

The tests no longer replace the outbox signal with ResilientOutboxSignal, and the helper is removed.
…Contexts

These tests need both the polling interval and the outbox processor per DbContext. The repeated registration tests check that the polling interval validation is registered once and that the second configure delegate is applied and validated. The relay clock tests register their outbox signal with the DbContext type as key, and the multiple context tests keep an idle relay from polling.
…t wrote no outbox message

Every SaveChanges and every transaction commit on an outbox context signaled the outbox processor, so the processor queried the outbox table after each of them, whether or not a message was written. The outbox now marks its context when it writes a message inside a database transaction, and the commit interceptor signals only when the mark is set. OutboxSaveChangesInterceptor is removed, so a save no longer signals. An OutboxMessage entity that is added through the change tracker is found when the processor next checks the database.
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ mocha labels Nov 29, 2026
@PascalSenn
PascalSenn marked this pull request as ready for review November 29, 2026 13:38
@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

97.9% of changed lines covered (95/97)

File Covered Changed Patch %
…/Outbox/OutboxDbTransactionInterceptor.cs 7 9 77.8% 🔴
…/Mocha.EntityFrameworkCore.Postgres/Outbox/OutboxProcessor.cs 18 18 100.0% 🟢
…/Outbox/OutboxServiceCollectionExtensions.cs 19 19 100.0% 🟢
…/Outbox/PostgresMessageOutbox.cs 10 10 100.0% 🟢
…/Outbox/PostgresOutboxOptions.cs 1 1 100.0% 🟢
…/src/Mocha.EntityFrameworkCore.Postgres/Outbox/ThrowHelper.cs 8 8 100.0% 🟢
…/DbContextMessagingServicesExtensions.cs 1 1 100.0% 🟢
…/DbContextOptionsBuilderExtensions.cs 1 1 100.0% 🟢
…/Mocha.EntityFrameworkCore/MessageBusHostBuilderExtensions.cs 8 8 100.0% 🟢
…/MessagingDbContextOptionsConfiguration.cs 4 4 100.0% 🟢
…/MessagingDbContextOptionsExtension.cs 4 4 100.0% 🟢
…/src/Mocha.EntityFrameworkCore/MessagingDbContextServices.cs 2 2 100.0% 🟢
…/Outbox/OutboxDbContextRegistration.cs 1 1 100.0% 🟢
…/OutboxEntityFrameworkCorePersistenceBuilderExtensions.cs 11 11 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "fe294a7ad99f8aa17b65720d1d71d368d76f72e5",
  "files": [
    { "path": "src/Mocha/src/Mocha.EntityFrameworkCore/Outbox/OutboxDbTransactionInterceptor.cs", "ranges": [[28, 29]] }
  ]
}

Project coverage: 60.3% (333263/552761 lines)

This branch has not been deployed

No deployments
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.

2 participants