Skip to main content

puerto_kafka/
lib.rs

1//! The Kafka transport of Puerto projects with domain events (`puerto nuevo --eventos kafka`,
2//! ADR-0018 § 4): the publisher the outbox relay of `puerto-events` hands each event to, and the
3//! subscription each consumer reads. The outbox and the dead letters stay in Postgres
4//! (`puerto_sqlx::events`).
5//!
6//! - One topic per aggregate, `<KAFKA_TOPIC_PREFIX>.<aggregate_type>`, keyed by the aggregate id:
7//!   the events of one aggregate land in one partition, in the order the outbox holds them.
8//! - The payload is the event's JSON payload; the rest of the envelope travels in headers.
9//! - A consumer is a consumer group (`<prefix>.<consumer>`) on the topics of the event types it
10//!   subscribes to; the records of other types are skipped. Its offset is committed once the
11//!   outcome is settled, so what was not settled is delivered again after a restart.
12//! - A `Reintentar` is retried in process with the delivery policy's backoff, then dead-lettered: the
13//!   records behind it wait (a partition stalls), they are never handled ahead of it.
14//!
15//! ```ignore
16//! let kafka = ConfigKafka::from_env("tienda")?;
17//! kafka.asegurar_topics(&["producto"]).await?;
18//! Bucles::new(&config)
19//!     .relay(OutboxPostgres::new(pool.clone()), PublicadorKafka::new(&kafka)?)
20//!     .consumidor(
21//!         SuscripcionKafka::new(&kafka, "avisar_producto_nuevo", &["producto"], &[PRODUCTO_CREADO], descartados.clone())?,
22//!         AvisarProductoNuevo,
23//!         descartados,
24//!     )
25//! ```
26
27pub mod config;
28pub mod publicador;
29pub mod suscripcion;
30mod wire;
31
32pub use config::ConfigKafka;
33pub use publicador::PublicadorKafka;
34pub use rdkafka::error::KafkaError;
35pub use suscripcion::SuscripcionKafka;