Skip to main content

outbox_core/
lib.rs

1use crate::config::OutboxConfig;
2use crate::error::OutboxError;
3use crate::model::Event;
4use crate::object::{EventType, IdempotencyToken, Payload};
5use crate::storage::OutboxWriter;
6
7mod object;
8mod storage;
9mod error;
10mod config;
11mod model;
12mod processor;
13mod publisher;
14mod gc;
15mod manager;
16mod idempotency;
17mod service;
18
19/// # Warning
20/// This function performs a raw insert into the database WITHOUT checking the
21/// idempotency storage. It is kept only for backward compatibility.
22///
23/// For production use with deduplication, please migrate to [`service::OutboxService`].
24#[deprecated(
25    since = "0.2.0",
26    note = "SECURITY WARNING: This standalone function ignores idempotency checks.
27           Use `OutboxService::add_event` for safe, deduplicated event publishing.
28           This function is no longer recommended and will be removed in 0.3.0."
29)]
30pub async fn add_event<W, F>(
31    writer: &W,
32    event_type: &str,
33    payload: serde_json::Value,
34    config: &OutboxConfig,
35    provided_token: Option<String>,
36    get_event: F,
37) -> Result<(), OutboxError>
38where
39    W: OutboxWriter,
40    F: FnOnce() -> Option<Event>,
41{
42
43    let i_token = config.idempotency_strategy.invoke(provided_token, get_event).map(IdempotencyToken::new);
44
45    let event = Event::new(EventType::new(event_type), Payload::new(payload), i_token);
46    writer.insert_event(event).await
47}
48
49pub mod prelude {
50    pub use crate::storage::{OutboxStorage, OutboxWriter};
51    pub use crate::idempotency::storage::IdempotencyStorageProvider;
52    pub use crate::publisher::Transport;
53
54    pub use crate::processor::OutboxProcessor;
55    pub use crate::manager::OutboxManager;
56    pub use crate::config::{OutboxConfig, IdempotencyStrategy};
57    pub use crate::service::OutboxService;
58
59    pub use crate::model::{Event, EventStatus};
60    pub use crate::object::{EventId, EventType, Payload, IdempotencyToken};
61
62    pub use crate::error::OutboxError;
63
64    pub use crate::add_event;
65}