MVFC.Outbox.MySql 6.0.0

dotnet add package MVFC.Outbox.MySql --version 6.0.0
                    
NuGet\Install-Package MVFC.Outbox.MySql -Version 6.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MVFC.Outbox.MySql" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MVFC.Outbox.MySql" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MVFC.Outbox.MySql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MVFC.Outbox.MySql --version 6.0.0
                    
#r "nuget: MVFC.Outbox.MySql, 6.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MVFC.Outbox.MySql@6.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MVFC.Outbox.MySql&version=6.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MVFC.Outbox.MySql&version=6.0.0
                    
Install as a Cake Tool

MVFC.Outbox.MySql

🇧🇷 Leia em Português

CI codecov License Platform NuGet Version NuGet Downloads

Main guide · Playground

MySQL Outbox provider using Oracle's MySQL EF Core integration (MySql.EntityFrameworkCore).

Supports .NET 10 and .NET 11.

dotnet add package MVFC.Outbox.MySql

ProducerOnly saves messages; ConsumerProducer also starts the worker. Manual dispatch uses the same confirmation flow (IOutboxExecutionPersistence). For custom registration updates, see the 4.0.0 migration guide.

Configuration and usage

These example variables come from your application: services, configuration, connection, ct, order and topicId. Register your DbContext with UseMySQL and map model.AddOutboxTable() in OnModelCreating.

Resolve IOutboxPublisher and ApplicationDbContext in the same dependency injection (DI) scope.

using MVFC.Outbox.EntityFrameworkCore;
using MVFC.Outbox.EntityFrameworkCore.Extensions;
using MVFC.Outbox.Extensions;
using MVFC.Outbox.MySql;
using MVFC.Outbox.MySql.Extensions;
using MVFC.Outbox.Publishing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

services.AddDbContext<ApplicationDbContext>(db => db.UseMySQL(connection));
services.AddOutbox(configuration, outbox => outbox.ProducerOnly()
    .MapAggregate<Order, Guid>(order => order.Id, "order")
    .UseMySql<ApplicationDbContext>(connection));

// Same scoped ApplicationDbContext used by the publisher:
await using var transaction = await database.Database.BeginTransactionAsync(ct);
database.Orders.Add(order);
await publisher.For(order).To(topicId).EnqueueAsync(ct);
await publisher.ForEach(otherOrders).To(topicId).EnqueueAsync(ct);
await database.SaveChangesAsync(ct);
await transaction.CommitAsync(ct);

public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
    : DbContext(options)
{
    public DbSet<Order> Orders => Set<Order>();

    protected override void OnModelCreating(ModelBuilder model)
    {
        model.Entity<Order>().HasKey(order => order.Id);
        model.AddOutboxTable();
    }
}

public sealed record Order(Guid Id, decimal Total);
  • Using your application's context: UseMySql<ApplicationDbContext>(connection) uses your application's DbContext and transaction. EnqueueAsync returns Staged; call SaveChangesAsync and commit to save the messages.

    UseMySql(connection), without a context type, uses a separate Outbox-only context.

  • Retention: the worker removes processed records in limited batches (Advanced.CleanupInterval, Advanced.CleanupBatchSize). MySQL does not use native TTL for this cleanup.

Schema initialization and existing databases

Create the database before initializing the Outbox schema. When AddOutbox(...UseMySql...) is registered, resolve IOutboxSchemaInitializer directly. To initialize the schema in a separate deployment step, without configuring topics or starting a worker, use AddMySqlOutboxSchema:

using MVFC.Outbox.MySql;
using MVFC.Outbox.MySql.Extensions;
using MVFC.Outbox.Persistence;

services.AddMySqlOutboxSchema(connection);
await using var scope = provider.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<IOutboxSchemaInitializer>().InitializeAsync(ct);
  • InitializeAsync can run repeatedly (it is idempotent). It creates the outbox table if needed and adds missing indexes (ix_outbox_dispatch, ix_outbox_ready, ix_outbox_retry, ix_outbox_aggregate, ix_outbox_lease, ix_outbox_expiration) without changing other tables.

    Run it once per deployment step with credentials that allow creating tables and indexes (DDL).

  • Databases predating metadata columns: only if DestinationKind, ProjectId or AttributesJson is still missing, add the missing columns below, then apply the 6.0.0 migration. A complete 5.x database needs only the 6.0.0 migration.

ALTER TABLE outbox
    ADD COLUMN DestinationKind int NOT NULL DEFAULT 0,
    ADD COLUMN ProjectId varchar(256) NULL,
    ADD COLUMN AttributesJson longtext NULL;

Worker database operations

  • Reservation: selects with FOR UPDATE SKIP LOCKED, writes leases and commits a short READ COMMITTED transaction before delivery. Requires MySQL 8.0+, InnoDB and row-based replication; SKIP LOCKED is unsafe with statement-based replication.
  • Updates: renewal, completion and failure require the ID, current token and valid lease; each success increments Version. These updates and standard reservation do not call SaveChanges or save pending application entities.
  • EF model: table and column names follow your mapping. Global filters or custom converters use EF acquisition with a tracked save in the worker's separate scope. Other transitions remain conditional; selection is automatic.
  • Concurrency: locked rows are skipped. Priority and age order available rows, without guaranteeing completion order.

Run schema initialization to add ix_outbox_ready and ix_outbox_retry; use your own migrations for customized tables. The application controls its transaction and isolation level.

Upgrading to 6.0.0

Stop producers, workers and administrative writes; back up before migrating. This script starts from the default 5.x schema. Use your own migration for custom tables, schemas or physical fields. Recompile consumers with EventType, Attributes, RetryCount and Error. See the contract and rollback.

ALTER TABLE outbox
    RENAME COLUMN `TopicId` TO `EventType`,
    RENAME COLUMN `AttributesJson` TO `Attributes`,
    RENAME COLUMN `Attempts` TO `RetryCount`,
    RENAME COLUMN `LastErrorCode` TO `Error`,
    ADD COLUMN `ClaimedAtUtc` datetime(6) NULL;

Run once against the 5.x table before starting version 6. Initialization creates new tables but does not apply this migration to existing ones. ClaimedAtUtc remains null in old rows; the next claim fills it. Existing indexes are retained.

Requirements

  • An application targeting .NET 10 or .NET 11.

  • Access to a MySQL database with transactional tables and an EF Core context configured with the MySQL provider. Schema initialization needs permission to create the Outbox table and indexes.

  • For development, use the .NET 11 SDK in global.json and .NET 10 targeting support. The playground and integration tests also require Docker. See the playground guide.

Contributing

See CONTRIBUTING.md for setup, Cake builds, tests and coverage conventions. Dependencies are listed in Directory.Packages.props.

License

Distributed under the Apache License 2.0. See LICENSE for all terms: permissions, redistribution conditions, and limits on warranty and liability.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 0 12/4/2026
5.0.0 74 12/3/2026
4.1.0 72 12/2/2026
4.0.0 87 12/1/2026
3.0.0 89 12/1/2026
2.0.1 96 11/30/2026
2.0.0 90 11/30/2026
1.1.1 93 11/30/2026
1.1.0 95 11/30/2026
1.0.1 93 11/30/2026
1.0.0 91 11/30/2026