Trait nakadion::BatchHandler[][src]

pub trait BatchHandler {
    fn handle(
        &mut self,
        event_type: EventType,
        events: &[u8]
    ) -> ProcessingStatus; }

A handler that contains batch processing logic.

This trait will be called by Nakadion when a batch has to be processed. The BatchHandler only receives an EventType and a slice of bytes that contains the batch.

The events slice always contains a JSON encoded array of events.

Hint

The handle method gets called on &mut self.

Example

use nakadion::{BatchHandler, EventType, ProcessingStatus};

// Use a struct to maintain state
struct MyHandler {
    pub count: i32,
}

// Implement the processing logic by implementing `BatchHandler`
impl BatchHandler for MyHandler {
    fn handle(&mut self, _event_type: EventType, _events: &[u8]) -> ProcessingStatus {
        self.count += 1;
        ProcessingStatus::processed_no_hint()
    }
}

// Handler creation will be done by `HandlerFactory`
let mut handler = MyHandler { count: 0 };

// This will be done by Nakadion
let status = handler.handle(EventType::new("test_event"), &[]);

assert_eq!(handler.count, 1);
assert_eq!(status, ProcessingStatus::Processed(None));

Required Methods

Handle the events.

Calling this method may never panic!

Implementors