Crate thalo_kafka

Source
Expand description

Kafka event stream for consuming events for Thalo apps.

For more information on watching events with Kafka, see spawn_event_handlers.

§Example

use thalo_kafka::spawn_event_handlers;

use crate::projections::{BankAccountProjection, AssetsProjection};

mod projections;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt().init();

    let kafka_host = std::env::var("KAFKA_HOST").expect("missing kafka_host env var");
    let database_url = std::env::var("DATABASE_URL").expect("missing database_url env var");
     
    let db = Database::connect(&database_url).await?;

    let handles = spawn_event_handlers!(
        kafka_host,
        ("bank-account", BankAccountProjection::new(db.clone())),
        ("assets", AssetsProjection::new(db)),
    );
     
    for handle in handles {
        handle.await??;
    }

    Ok(())
}

Macros§

spawn_event_handlers
Spawn multiple event handlers in separate tokio tasks and returns a vector of the join handles.

Structs§

KafkaClientConfig
A wrapper around rdkafka::ClientConfig for convenience.
KafkaEventMessage
A message received from Kafka including the event and raw Kafka message.
KafkaEventStream
An event stream consuming from kafka.

Enums§

Error
Error enum.

Traits§

Topic
A Kafka topic.
WatchEventHandler
Watch an event handler and apply incoming events.