#kafka #notifications #events #webhook

event-notification

A modular event notification system with multi-channel support

4 releases (2 breaking)

Uses new Rust 2024

new 0.4.1 Apr 20, 2025
0.4.0 Apr 20, 2025
0.3.0 Apr 19, 2025
0.2.0 Apr 19, 2025

#272 in Asynchronous

Download history 411/week @ 2025-04-15

411 downloads per month

MIT/Apache

54KB
1K SLoC

Event Notification

English | 简体中文

A modular event notification system with multi-channel support for Rust applications.

Crates.io Docs.rs License Rust

Features

  • Modular notification system with pluggable channel adapters
  • Supports multiple delivery channels (Webhook, Kafka, MQTT)
  • Asynchronous event processing with Tokio
  • Simple global initialization pattern for cross-crate usage
  • Event persistence and history management
  • Flexible configuration options

Installation

Add this to your Cargo.toml:

[dependencies]
event-notification = "0.4.0"

Enable specific adapters with features:

[dependencies]
event-notification = { version = "0.4.0", features = ["webhook", "kafka", "mqtt"] }

Quick Start

use event_notification::{initialize, send_event, start, Event, Identity, Name, NotificationConfig};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // 1. Configure the notification system
    let config = NotificationConfig {
        store_path: "./events".to_string(),
        channel_capacity: 100,
        adapters: vec![
            // Configure your adapters here
        ],
    };

    // 2. Initialize the global notification system
    initialize(config.clone()).await?;

    // 3. Start the system with adapters
    let adapters = event_notification::create_adapters(&config.adapters)?;
    start(adapters).await?;

    // 4. Send events from anywhere in your application
    let event = Event::builder()
        .event_time("2023-10-01T12:00:00.000Z")
        .event_name(Name::ObjectCreatedPut)
        .user_identity(Identity {
            principal_id: "user123".to_string(),
        })
        .build()?;

    send_event(event).await?;

    // 5. Shutdown gracefully when done
    tokio::signal::ctrl_c().await?;
    event_notification::shutdown()?;

    Ok(())
}

Supported Adapters

Webhook

Send events to HTTP endpoints:

use event_notification::{AdapterConfig, WebhookConfig};

let webhook_config = WebhookConfig {
endpoint: "https://example.com/webhook".to_string(),
headers: Some(vec![
    ("Authorization".to_string(), "Bearer token123".to_string()),
    ("Content-Type".to_string(), "application/json".to_string()),
]),
timeout_ms: Some(5000),
};

let adapter_config = AdapterConfig::Webhook(webhook_config);

Kafka

Publish events to Kafka topics:

use event_notification::{AdapterConfig, KafkaConfig};

let kafka_config = KafkaConfig {
bootstrap_servers: "localhost:9092".to_string(),
topic: "notifications".to_string(),
client_id: Some("my-app".to_string()),
};

let adapter_config = AdapterConfig::Kafka(kafka_config);

MQTT

Publish events to MQTT topics:

use event_notification::{AdapterConfig, MqttConfig};

let mqtt_config = MqttConfig {
broker_url: "mqtt://localhost:1883".to_string(),
client_id: "event-system".to_string(),
topic: "events".to_string(),
qos: 1,
};

let adapter_config = AdapterConfig::Mqtt(mqtt_config);

Using Across Multiple Crates

Initialize once in your main application:

// main.rs or lib.rs
event_notification::initialize(config).await?;
let adapters = event_notification::create_adapters( & config.adapters) ?;
event_notification::start(adapters).await?;

Then use from any other crate:

// any other module or crate
use event_notification::{send_event, Event};

pub async fn process() -> Result<(), Box<dyn std::error::Error>> {
    let event = Event::builder()
        // Configure event
        .build()?;

    send_event(event).await?;
    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~9–24MB
~363K SLoC