Skip to main content

DispatchMode

Enum DispatchMode 

Source
pub enum DispatchMode {
    Broadcast,
    Channel,
}
Expand description

Dispatch mode for configuring event routing (Broadcast or Channel) Event routing mode for distributing changes to subscribers

DispatchMode determines how events are routed from sources to queries and from queries to reactions. It affects memory usage, throughput, and fanout behavior.

§Modes

§Broadcast Mode

Uses a single shared channel with multiple receivers (1-to-N fanout):

Source → [Broadcast Channel] → Query 1
                             → Query 2
                             → Query 3

Advantages:

  • Lower memory usage (one copy of each event)
  • Better for high-fanout scenarios (many subscribers)
  • Automatic backpressure when slowest subscriber lags

Disadvantages:

  • All subscribers receive all events (no filtering)
  • Slowest subscriber can slow down entire system
  • Events may be dropped if buffers fill

§Channel Mode (Default)

Uses dedicated channels per subscriber (1-to-1):

Source → [Channel 1] → Query 1
      → [Channel 2] → Query 2
      → [Channel 3] → Query 3

Advantages:

  • Subscribers process independently
  • Slow subscriber doesn’t affect others
  • More predictable behavior

Disadvantages:

  • Higher memory usage (one copy per subscriber)
  • More overhead for high-fanout scenarios

§Configuration

Set in YAML configuration or via builder API:

sources:
  - id: data_source
    source_type: postgres
    dispatch_mode: broadcast  # or channel (default)

queries:
  - id: my_query
    query: "MATCH (n) RETURN n"
    sources: [data_source]
    dispatch_mode: channel

§Choosing a Mode

Use Broadcast when:

  • High fanout (10+ subscribers)
  • All subscribers need all events
  • Memory is constrained
  • All subscribers process at similar speeds

Use Channel (default) when:

  • Few subscribers (1-5)
  • Subscribers have different processing speeds
  • Isolation between subscribers is important
  • Memory is not constrained

§Examples

§Builder API Configuration

use drasi_lib::{DrasiLib, Query, DispatchMode};

// Sources are now instance-based - create them externally and use .with_source()
let core = DrasiLib::builder()
    // .with_source(my_source_instance)
    .with_query(
        Query::cypher("active_orders")
            .query("MATCH (o:Order) WHERE o.status = 'active' RETURN o")
            .from_source("orders_db")
            .with_dispatch_mode(DispatchMode::Channel)    // Default, independent processing
            .build()
    )
    .build()
    .await?;

§High-Fanout Scenario (Use Broadcast)

sources:
  - id: event_stream
    source_type: http
    host: localhost
    port: 8080
    dispatch_mode: broadcast  # Many queries subscribe to this source

queries:
  - id: query1
    query: "MATCH (n:Type1) RETURN n"
    sources: [event_stream]
  - id: query2
    query: "MATCH (n:Type2) RETURN n"
    sources: [event_stream]
  # ... 20 more queries subscribing to event_stream

§Independent Processing (Use Channel)

sources:
  - id: sensor_data
    source_type: mock
    dispatch_mode: channel  # Default - each query processes independently

queries:
  - id: real_time_alerts
    query: "MATCH (s:Sensor) WHERE s.value > 100 RETURN s"
    sources: [sensor_data]
    # Fast processing

  - id: historical_analysis
    query: "MATCH (s:Sensor) RETURN s"
    sources: [sensor_data]
    # Slow processing - won't affect real_time_alerts

§Performance Considerations

Broadcast Memory Usage: O(buffer_size) - single buffer shared Channel Memory Usage: O(buffer_size * subscribers) - buffer per subscriber

For 10 subscribers with 1000-event buffers:

  • Broadcast: ~1,000 events in memory
  • Channel: ~10,000 events in memory

Variants§

§

Broadcast

Broadcast mode: single channel with multiple receivers (1-to-N fanout)

§

Channel

Channel mode: dedicated channel per subscriber (1-to-1)

Trait Implementations§

Source§

impl Clone for DispatchMode

Source§

fn clone(&self) -> DispatchMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DispatchMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DispatchMode

Source§

fn default() -> DispatchMode

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DispatchMode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for DispatchMode

Source§

fn eq(&self, other: &DispatchMode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DispatchMode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for DispatchMode

Source§

impl Eq for DispatchMode

Source§

impl StructuralPartialEq for DispatchMode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,