Skip to main content

EventSubscriber

Trait EventSubscriber 

Source
pub trait EventSubscriber: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn handle<'a>(&'a self, event: &'a Event) -> SubscriberFuture<'a>;
}
Expand description

A subscriber that reacts to domain events.

Implement this trait to create custom notification channels (Slack, Discord, PagerDuty, etc.). The engine broadcasts events to all registered subscribers via EventPublisher.

§Contract

  • handle is called only for events that match the filter configured at subscription time.
  • Implementations must not block – heavy work should be spawned.
  • Errors are logged internally; they must not propagate.

§Examples

use ironflow_engine::notify::{EventSubscriber, Event, SubscriberFuture};

struct LogSubscriber;

impl EventSubscriber for LogSubscriber {
    fn name(&self) -> &str { "log" }

    fn handle<'a>(&'a self, event: &'a Event) -> SubscriberFuture<'a> {
        Box::pin(async move {
            println!("[{}] {:?}", event.event_type(), event);
        })
    }
}

Required Methods§

Source

fn name(&self) -> &str

A short identifier for this subscriber (used in logs).

Source

fn handle<'a>(&'a self, event: &'a Event) -> SubscriberFuture<'a>

Handle a domain event.

Only called for events matching the filter set at subscription time. The subscriber does not need to filter.

Implementors§