Skip to main content

Crate puerto_kafka

Crate puerto_kafka 

Source
Expand description

The Kafka transport of Puerto projects with domain events (puerto nuevo --eventos kafka, ADR-0018 § 4): the publisher the outbox relay of puerto-events hands each event to, and the subscription each consumer reads. The outbox and the dead letters stay in Postgres (puerto_sqlx::events).

  • One topic per aggregate, <KAFKA_TOPIC_PREFIX>.<aggregate_type>, keyed by the aggregate id: the events of one aggregate land in one partition, in the order the outbox holds them.
  • The payload is the event’s JSON payload; the rest of the envelope travels in headers.
  • A consumer is a consumer group (<prefix>.<consumer>) on the topics of the event types it subscribes to; the records of other types are skipped. Its offset is committed once the outcome is settled, so what was not settled is delivered again after a restart.
  • A Reintentar is retried in process with the delivery policy’s backoff, then dead-lettered: the records behind it wait (a partition stalls), they are never handled ahead of it.
ⓘ
let kafka = ConfigKafka::from_env("tienda")?;
kafka.asegurar_topics(&["producto"]).await?;
Bucles::new(&config)
    .relay(OutboxPostgres::new(pool.clone()), PublicadorKafka::new(&kafka)?)
    .consumidor(
        SuscripcionKafka::new(&kafka, "avisar_producto_nuevo", &["producto"], &[PRODUCTO_CREADO], descartados.clone())?,
        AvisarProductoNuevo,
        descartados,
    )

Re-exports§

pub use config::ConfigKafka;
pub use publicador::PublicadorKafka;
pub use suscripcion::SuscripcionKafka;

Modules§

config
Where the brokers are and how topics are named, read once at startup from the environment (and .env).
publicador
The relay’s output on the Kafka transport.
suscripcion
A consumer’s input on the Kafka transport.

Enums§

KafkaError
Represents all possible Kafka errors.