Spanner Outbox
Reference · Applies to Brighter V10 · Prerequisites: Outbox Support
The Spanner Outbox stores messages in a Google Cloud Spanner table, and it is configured entirely through the shared relational configuration. Spanner's strong consistency makes the Outbox write and the business write one atomic commit.
Spanner Outbox Configuration
dotnet add package Paramore.Brighter.Outbox.Spanner
dotnet add package Paramore.Brighter.SpannerThe Spanner Outbox has no options type of its own. SpannerOutbox takes an IAmARelationalDatabaseConfiguration, which is the same type every relational Outbox, Inbox, provisioner and queue-table transport takes — so its options are documented once, at Relational Database Configuration Reference. This page has no option table because there is no Spanner-specific surface to tabulate; what follows is what Spanner does differently with the options that page lists.
Register the configuration against the interface as well as passing it to the Outbox: the provisioner and the Sweeper resolve it from the container, and producers.ConnectionProvider and producers.TransactionProvider take a Type the container activates.
using Microsoft.Extensions.DependencyInjection;
using Paramore.Brighter;
using Paramore.Brighter.Extensions.DependencyInjection;
using Paramore.Brighter.Outbox.Hosting;
using Paramore.Brighter.Outbox.Spanner;
using Paramore.Brighter.Spanner;
public static class SpannerOutboxRegistration
{
public static void ConfigureServices(IServiceCollection services)
{
var configuration = new RelationalDatabaseConfiguration(
connectionString: "Data Source=projects/my-project/instances/my-instance/databases/brighter",
outBoxTableName: "Outbox");
services.AddSingleton<IAmARelationalDatabaseConfiguration>(configuration);
services.AddBrighter()
.AddProducers(producers =>
{
producers.Outbox = new SpannerOutbox(configuration);
producers.ConnectionProvider = typeof(SpannerConnectionProvider);
producers.TransactionProvider = typeof(SpannerUnitOfWork);
// ... your producer registry
})
.UseOutboxSweeper()
.AutoFromAssemblies();
}
}Two of the relational options behave differently here, and both change the table rather than the code:
binaryMessagePayloadselectsBYTES(MAX)for theBodycolumn instead ofSTRING(MAX). The two shapes are not interchangeable, so this is a decision made when the table is created.schemaNameis not used here. Spanner does not organise tables into schemas the way the other relational backends do, and its provisioning extensions take noschemaNameargument where the other four do.
Provisioning the Spanner Outbox
You have the same two options every relational Outbox has, with one Spanner caveat on the first.
Option A — let Brighter provision it. AddSpannerOutbox registers a provisioner that creates the table at startup; see Configuring Box Provisioning. Spanner uses the degenerate runner: it creates the table on a fresh database and cannot evolve an existing one. There is no migration chain to run and MigrationLockTimeout is ignored, because Spanner serialises DDL itself. An existing Spanner Outbox that predates a Brighter release therefore needs its new columns added by hand — see Per-backend differences to be aware of.
Option B — manage the DDL yourself. SpannerOutboxBuilder.GetDDL() returns the DDL Brighter ships, which you can drive through your own change-management tooling:
The table is keyed on MessageId and uses GoogleSQL types throughout:
CausationId arrives at Brighter 10.8.0, and its index is a separate statement, since Spanner has no inline index syntax: SpannerOutboxBuilder.GetCausationIndexDDL("Outbox") returns
A table an earlier release created still takes deposits without them, but Replay On Seen needs both. The Spanner provisioner creates them only on a fresh install, so add them by hand to an existing table.
Spanner Connection Provider
SpannerConnectionProvider opens the connections the Outbox reads and writes on, and SpannerUnitOfWork is the transaction provider that lets your business write and the Outbox write share one Spanner transaction. Both take the same IAmARelationalDatabaseConfiguration, and SpannerOutbox builds a SpannerConnectionProvider for you if you construct it with the configuration alone.
Both set EmulatorDetection.EmulatorOrProduction on the connection string. That means a SPANNER_EMULATOR_HOST environment variable routes the connection to the emulator, and its absence routes to production — you do not change the connection string between the two. It is the one place the Spanner packages add a keyword to what you supply.
Two Spanner behaviours worth knowing when you read a stack trace:
A command timeout of zero is replaced by 60 seconds. Spanner rejects a zero timeout, so the Outbox substitutes 60 rather than passing it through.
Duplicate keys surface as
SpannerExceptionwith anAlreadyExistsstatus, which Brighter translates into its usual duplicate-message handling.
Further Reading
Relational Database Configuration Reference — every option this Outbox takes
Outbox Support — what an Outbox is for and how the Sweeper dispatches from it
Spanner Inbox — the same configuration type, one family over
Database Provisioning — the migration machinery, and why Spanner's runner is degenerate
Replay On Seen Reference — the causation column an existing Spanner table needs adding by hand
Last updated
Was this helpful?
