constellation-rs / amadeus

Harmonious distributed data analysis in Rust.
https://constellation.rs/amadeus
Apache License 2.0
474 stars 26 forks source link

Kinesis/Kafka/NATS as Sources #56

Open alecmocatta opened 4 years ago

alecmocatta commented 4 years ago

Proposed design for consuming from Kafka/Kinesis:

A simple auto scaling Kafka example that starts with 10 consumers, growing and shrinking to reach the specified acceptable lag:

use amadeus::prelude::*;

#[tokio::main]
async fn main() {
    let pool = ThreadPool::new()?;

    let messages = Kafka::new(vec!["localhost:9092".parse().unwrap()])
        .with_topic("my-topic".to_owned())
        .with_group("my-group".to_owned())
        .with_consumers(10)
        .with_target_records_lag(10_000)
        .build().await?;

    messages
        .par_stream()
        .for_each(|messages: Result<KafkaMessageSet, _>| async {
            let messages = messages.expect("kafka error");
            for msg in &messages {
                println!("received message {}: {} {}", msg.offset, msg.key, msg.value);
            }
            messages.consume();
            messages.commit();
        });

    panic!("All Kafka consumers have died");
}

Need clarification:

Assumptions: