Skip to main content

Crate snodra_messaging_sqlx

Crate snodra_messaging_sqlx 

Source
Expand description

The SQL message store: 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 specification’s SQL layout: same tables, same values, same meanings as every Snodra library’s SQL store, so services written with any of them 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 specification’s reference files, byte for byte (schema::POSTGRESQL_V1, schema::MYSQL_V1). start() applies it (MessageStore::init_schema: the server checked, then V1 under a database lock unless snodra_schema holds version 1 or later) unless SNODRA_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 the Config.

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 specification’s reference files (db/snodra/<dialect>/V1__snodra.sql, byte for byte).

Structs§

SqlxSettings
How the SQL store runs beside its tables.
SqlxStore
The SQL message store: see the crate docs. Every clone is the same store.

Traits§

SqlxTxExt
The connection of a Tx of the SQL store, in its transaction, for a handler’s own writes in the transaction of the message it handles: