tana-event-bus

Crates.iotana-event-bus
lib.rstana-event-bus
version0.2.1
created_at2025-11-25 01:25:49.087253+00
updated_at2025-12-07 00:01:43.045627+00
descriptionRust client library for Tana Event Bus
homepage
repositoryhttps://github.com/tananetwork/tana-event-bus
max_upload_size
id1949010
size56,778
Sami Fouad (samifouad)

documentation

README

tana-event-bus

Rust client library for dispatching events to the Tana Event Bus server.

Installation

Add to your Cargo.toml:

[dependencies]
tana-event-bus = "0.1"

Usage

use tana_event_bus::{dispatch_event, Event, EventLevel, configure};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Optional: Configure once at startup
    configure(
        Some("http://events.tana.network:8508"),
        Some(10), // timeout seconds
        Some(5)   // max retries
    )?;

    // Dispatch an event
    let response = dispatch_event(Event {
        service: "edge".to_string(),
        level: EventLevel::Info,
        category: "contract_execution".to_string(),
        message: "Contract executed successfully".to_string(),
        timestamp: None, // Will be set automatically
        metadata: Some(json!({
            "contract_id": "abc123",
            "duration_ms": 45
        })),
    }).await?;

    println!("Event ID: {:?}", response.message_id);
    Ok(())
}

Fire-and-Forget

For high-frequency events where you don't need confirmation:

use tana_event_bus::{dispatch_event_async, Event, EventLevel};

fn handle_request() {
    // Non-blocking dispatch
    dispatch_event_async(Event {
        service: "edge".to_string(),
        level: EventLevel::Debug,
        category: "performance".to_string(),
        message: "Request processed".to_string(),
        timestamp: None,
        metadata: None,
    });
}

Configuration

The client can be configured via:

  1. Environment variable: EVENT_BUS_URL (default: http://localhost:8508)
  2. Code: configure() function

License

MIT

Commit count: 0

cargo fmt