1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use Uuid;
use crateOutboxError;
/// Contract for inserting a pre-serialized event into the outbox idempotently.
///
/// Unlike [`OutboxPublisher`](crate::OutboxPublisher), which takes a typed
/// [`Event`](crate::Event) and serializes it, this trait accepts the raw
/// `event_type` and `payload` already produced upstream, together with a
/// caller-supplied `event_id`. The insert is keyed on `event_id` and is a
/// no-op when a row with that identifier already exists, so the same logical
/// event can be enqueued more than once without producing a duplicate row.
///
/// # Idempotency key
///
/// The caller owns the meaning of `event_id`. A producer that may replay the
/// same logical event (for example a scheduler redelivering a due occurrence
/// after a crash) should derive a stable, content-addressed identifier so the
/// retries collapse onto a single row. The backend relies on the unique index
/// over `event_id` to reject the duplicate silently.
///
/// # Ordering
///
/// The outbox worker polls by ascending `event_id` (a `UUIDv7` carries an
/// embedded timestamp). A caller that supplies an identifier of another kind
/// trades that insertion-order property for deterministic idempotency; the
/// rows are still delivered, only their relative poll order is unspecified.