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 3Advantages:
- 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 3Advantages:
- 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
impl Clone for DispatchMode
Source§fn clone(&self) -> DispatchMode
fn clone(&self) -> DispatchMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DispatchMode
impl Debug for DispatchMode
Source§impl Default for DispatchMode
impl Default for DispatchMode
Source§fn default() -> DispatchMode
fn default() -> DispatchMode
Source§impl<'de> Deserialize<'de> for DispatchMode
impl<'de> Deserialize<'de> for DispatchMode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for DispatchMode
impl PartialEq for DispatchMode
Source§impl Serialize for DispatchMode
impl Serialize for DispatchMode
impl Copy for DispatchMode
impl Eq for DispatchMode
impl StructuralPartialEq for DispatchMode
Auto Trait Implementations§
impl Freeze for DispatchMode
impl RefUnwindSafe for DispatchMode
impl Send for DispatchMode
impl Sync for DispatchMode
impl Unpin for DispatchMode
impl UnwindSafe for DispatchMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.