SqlMessageStorage
Persists cluster mailbox messages and replies in SQL.
The SQL-backed MessageStorage stores encoded cluster envelopes and reply chunks so runners can recover mailbox state after restarts. It supports redelivering unprocessed messages, deduplicating requests by primary key, and replaying reply chunks until they are acknowledged. This module includes the storage constructor, layers, migrations, optional table prefixes, and the row mapping needed by encoded message storage.
Request deduplication keys that exceed the 255-character message_id column are hashed with the Crypto service before they are written, so composed keys of any length are supported; shorter keys are stored as plaintext, byte-compatible with rows written by previous versions.
Constructors
Layers
Layer that provides SQL-backed MessageStorage using the default table prefix and the default snowflake generator.
When to use
Use when a cluster should persist mailbox messages and replies in SQL using the default cluster table prefix and the standard snowflake generator.
Details
The layer runs the SQL migrations through make, provides MessageStorage, and supplies Snowflake.layerGenerator internally. Callers still provide SqlClient, ShardingConfig, and Crypto.Crypto, which is used to hash message deduplication keys that would overflow the fixed-width message_id column.
Gotchas
This layer always uses the cluster table prefix. Use layerWith before deployment if you need a different stable prefix, because changing prefixes later points the runtime at a different set of tables.
See
Signature
declare const layer: Layer.Layer<
MessageStorage.MessageStorage,
never,
SqlClient.SqlClient | ShardingConfig | Crypto.Crypto
>;Layer that provides SQL-backed MessageStorage using a custom table prefix.
Signature
declare function layerWith(options: {
readonly prefix?: string;
}): Layer<MessageStorage, never, Crypto | ShardingConfig | SqlClient>;
Creates a SQL-backed
MessageStorageimplementation, running its migrations and using the optional table prefix.When to use
Use when you need the SQL-backed
MessageStorageservice directly, such as when composing a custom layer or providing your ownSnowflake.Generator.Details
The optional
prefixcontrols the table names for messages, replies, and migrations; when omitted,clusteris used.Gotchas
Changing
prefixafter deployment points the runtime at a different set of tables, including the migration history table.See
layerfor a ready-made layer using the default prefix and generatorlayerWithfor a ready-made layer with a custom table prefix