#event #broker #distributed #messaging #nakadi

nakadion

Types for interacting with the Nakadi Event Broker

108 releases (20 breaking)

✓ Uses Rust 2018 edition

new 0.26.1 May 21, 2020
0.25.4 May 15, 2020
0.20.1 Mar 6, 2020
0.15.0 Dec 10, 2019
0.3.4 Apr 24, 2017

#13 in Math

Download history 16/week @ 2020-01-25 5/week @ 2020-02-01 85/week @ 2020-02-08 170/week @ 2020-02-15 529/week @ 2020-02-22 55/week @ 2020-02-29 203/week @ 2020-03-07 104/week @ 2020-03-14 481/week @ 2020-03-21 19/week @ 2020-03-28 104/week @ 2020-04-04 403/week @ 2020-04-11 107/week @ 2020-04-18 65/week @ 2020-04-25 116/week @ 2020-05-02 202/week @ 2020-05-09

829 downloads per month

Apache-2.0/MIT

650KB
15K SLoC

NakadiOn!

CI

A client for the Nakadi Event Broker.

Summary

Nakadion is client that connects to the Nakadi Subscription API. It does all the cursor management so that users can concentrate on implementing their logic for processing events. The code implemented to process events by a user does not get in touch with the internals of Nakadi.

Nakadion is almost completely configurable from environment variables.

Please have a look at the documentation of Nakadi first to become comfortable with the concepts of Nakadi.

Currently Nakadion only works with the tokio runtime. Further execution environments might be added in the future.

How to use

To run this example the following environment variables need to be set:

  • NAKADION_NAKADI_BASE_URL
  • NAKADION_SUBSCRIPTION_ID
  • NAKADION_ACCESS_TOKEN_FIXED with a valid token or NAKADION_ACCESS_TOKEN_ALLOW_NONE=true
use nakadion::api::ApiClient;
use nakadion::consumer::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ApiClient::builder().finish_from_env()?;

    let consumer = Consumer::builder_from_env()?.build_with(
        client,
        handler::MyHandlerFactory,
        StdOutLogger::default(),
    )?;

    let (_handle, consuming) = consumer.start();

    let _ = consuming.await.into_result()?;

    Ok(())
}

mod handler {
    use futures::future::{BoxFuture, FutureExt};

    use nakadion::handler::*;

    pub struct MyHandler {
        events_received: usize,
    }

    impl EventsHandler for MyHandler {
        type Event = serde_json::Value;
        fn handle<'a>(
            &'a mut self,
            events: Vec<Self::Event>,
            _meta: BatchMeta<'a>,
        ) -> EventsHandlerFuture {
            async move {
                self.events_received += events.len();
                EventsPostAction::Commit
            }
            .boxed()
        }
    }

    pub struct MyHandlerFactory;

    impl BatchHandlerFactory for MyHandlerFactory {
        fn handler(
            &self,
            _assignment: &HandlerAssignment,
        ) -> BoxFuture<Result<Box<dyn BatchHandler>, Error>> {
            async { Ok(Box::new(MyHandler { events_received: 0 }) as Box<_>) }.boxed()
        }
    }
}

Performance

Nakadion is not meant to be used in a high performance scenario. It uses asynchronous IO. Nevertheless it is easily possible to consume tens of thousands events per second depending on the complexity of your processing logic.

Recent Changes

See CHANGELOG

License

Nakadion is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

License: Apache-2.0/MIT

Dependencies

~6.5–10MB
~207K SLoC