pub trait TransactionalEventHandler:
Send
+ Sync
+ 'static {
type Aggregate: Aggregate;
// Required method
fn handle(
&self,
event: HandledEvent<<Self::Aggregate as Aggregate>::Event>,
conn: &mut PgConnection,
) -> impl Future<Output = Result<()>> + Send;
}Expand description
A read-model handler that writes inside the runner’s checkpoint transaction (review C2/LEASE-1).
The runner runs handle and the fenced lease checkpoint in a single
Postgres transaction. If this worker has been fenced (a newer leader stole
the lease), the checkpoint matches 0 rows and the whole transaction —
including the handler’s read-model writes — rolls back. A paused, stale
leader therefore cannot land writes the new leader has already moved past,
which is the unfenced-handler corruption a plain EventHandler is open
to. Net effect: effectively-exactly-once read-model updates for a
Postgres sink.
Register with ProjectionRunnerBuilder::subscribe_transactional. Your
handle must do all its read-model writes via the supplied conn (e.g.
sqlx::query(...).execute(&mut *conn)) — writes on any other connection
are not covered by the fence.
Required Associated Types§
Required Methods§
fn handle( &self, event: HandledEvent<<Self::Aggregate as Aggregate>::Event>, conn: &mut PgConnection, ) -> impl Future<Output = Result<()>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".