Trait nakadion::TypedBatchHandler[][src]

pub trait TypedBatchHandler {
    type Event: DeserializeOwned;
    fn handle(&mut self, events: Vec<Self::Event>) -> TypedProcessingStatus;

    fn handle_deserialization_errors(
        &mut self,
        results: Vec<EventDeserializationResult<Self::Event>>
    ) -> TypedProcessingStatus { ... } }

Basically the same a BatchHandler with the difference that deserialized events are passed to the processing logic.

This is basically a convinience handler.

The events must implement serdes DeserializeOwned.

Hint

The handle method gets called on &mut self.

Example

/// use nakadion::{EventType, TypedBatchHandler, TypedProcessingStatus};

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

#[derive(Deserialize)]
struct MyEvent(i32);

// Implement the processing logic by implementing `BatchHandler`
impl TypedBatchHandler for MyHandler {
    type Event = MyEvent;

    fn handle(&mut self, events: Vec<MyEvent>) -> TypedProcessingStatus {
        for MyEvent(amount) in events {
            self.count += amount;
        }
        TypedProcessingStatus::Processed
    }
}

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

// This will be done by Nakadion
handler.handle(vec![MyEvent(1), MyEvent(2)]);

assert_eq!(handler.count, 3);

Associated Types

Required Methods

Execute the processing logic with a deserialized batch of events.

Provided Methods

Implementors