Expand description
The SQL message store (ADR 0028): every store of snodra_messaging::store over the service’s
own PostgreSQL (13 or later, feature postgres) or MySQL (8.0.17 or later, InnoDB, feature
mysql) database through sqlx, in the tables snodra-messaging-jdbc (the Kotlin twin)
writes: same tables, same values, same meanings, so a Kotlin service and a Rust service can
share one database.
ⓘ
let pool = sqlx::postgres::PgPoolOptions::new().max_connections(10).connect(&url).await?;
let app = SnodraMessaging::builder(config).await?
.store(Arc::new(SqlxStore::postgres(pool).with_settings(SqlxSettings::from_env()?)))
/* ... */;- Schema:
db/snodra/<dialect>/V1__snodra.sql, the files snodra-messaging-jdbc ships, byte for byte (schema::POSTGRESQL_V1,schema::MYSQL_V1).start()applies it (MessageStore::init_schema: the server checked, then V1 under a database lock unlesssnodra_schemaholds version 1 or later) unlessSNODRA_STORE_INIT_SCHEMA=false; then it checks that the database has version 1 or later (MessageStore::check_schema). - Transactions: the store’s transactions are transactions on connections of the pool. A
handler writes its own rows in the transaction of the message it handles with
SqlxTxExt(ctx.tx.lock().await.connection::<Postgres>()): its rows, the outbox entries and the processed-event markers commit or roll back together. What commits on its own (dead letters, processor control, the relays’ and schedulers’ claims, the purge) runs in a transaction of its own at READ COMMITTED; a store call outside any transaction in a short one of its own. A connection whose transaction did not end cleanly is closed, never returned to the pool. - Wake-up (PostgreSQL): every append runs
SELECT pg_notify('snodra_outbox', '')in its transaction, and the relay listens (LISTEN snodra_outbox) on a connection of its own while it runs, so it publishes as soon as an append commits. MySQL: the relay polls. - Retention: what the MongoDB add-on’s TTL indexes do, a purge does every
SqlxSettings::purge_interval, with the retentions of theConfig.
Times are the application’s clock (the builder’s, MessageStore::use_clock), at
millisecond precision, UTC; never the database’s.
Modules§
- schema
- The schema of the SQL message store: the server check and the versioned schema files, the same
files snodra-messaging-jdbc ships (
db/snodra/<dialect>/V1__snodra.sql, byte for byte).
Structs§
- Sqlx
Settings - How the SQL store runs beside its tables.
- Sqlx
Store - The SQL message store: see the crate docs. Every clone is the same store.