pub struct StreamRouter { /* private fields */ }Expand description
Stream message router with content-, topic-, and header-based routing, round-robin distribution, priority ordering, and a dead-letter queue.
Implementations§
Source§impl StreamRouter
impl StreamRouter
Sourcepub fn new(config: RouterConfig) -> Self
pub fn new(config: RouterConfig) -> Self
Create a new router with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a router with default configuration.
Sourcepub fn add_rule(&mut self, rule: RoutingRule) -> Result<(), RouterError>
pub fn add_rule(&mut self, rule: RoutingRule) -> Result<(), RouterError>
Add a routing rule. Rules are kept sorted by descending priority.
Sourcepub fn remove_rule(&mut self, rule_id: &str) -> Result<RoutingRule, RouterError>
pub fn remove_rule(&mut self, rule_id: &str) -> Result<RoutingRule, RouterError>
Remove a routing rule by ID.
Sourcepub fn update_rule(&mut self, rule: RoutingRule) -> Result<(), RouterError>
pub fn update_rule(&mut self, rule: RoutingRule) -> Result<(), RouterError>
Update an existing rule in place.
Sourcepub fn set_rule_enabled(
&mut self,
rule_id: &str,
enabled: bool,
) -> Result<(), RouterError>
pub fn set_rule_enabled( &mut self, rule_id: &str, enabled: bool, ) -> Result<(), RouterError>
Enable or disable a rule.
Sourcepub fn stats(&self) -> &RoutingStats
pub fn stats(&self) -> &RoutingStats
Return a snapshot of current routing statistics.
Sourcepub fn active_rule_count(&self) -> usize
pub fn active_rule_count(&self) -> usize
Return the number of active (enabled) rules.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Return total number of rules.
Sourcepub fn dlq(&self) -> &VecDeque<RoutableMessage>
pub fn dlq(&self) -> &VecDeque<RoutableMessage>
Return the dead-letter queue contents.
Sourcepub fn pop_dlq(&mut self) -> Option<RoutableMessage>
pub fn pop_dlq(&mut self) -> Option<RoutableMessage>
Pop the oldest dead-lettered message.
Sourcepub fn route(&mut self, message: RoutableMessage) -> RoutingOutcome
pub fn route(&mut self, message: RoutableMessage) -> RoutingOutcome
Route a single message through the rule chain.
The first matching enabled rule (by priority) wins. If no rule matches, the message is dead-lettered (if DLQ is enabled).
Sourcepub fn route_batch(
&mut self,
messages: Vec<RoutableMessage>,
) -> Vec<RoutingOutcome>
pub fn route_batch( &mut self, messages: Vec<RoutableMessage>, ) -> Vec<RoutingOutcome>
Route a batch of messages. Returns one outcome per message.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset statistics counters to zero.
Sourcepub fn get_rule(&self, rule_id: &str) -> Option<&RoutingRule>
pub fn get_rule(&self, rule_id: &str) -> Option<&RoutingRule>
Return a reference to a rule by ID, if it exists.
Auto Trait Implementations§
impl Freeze for StreamRouter
impl RefUnwindSafe for StreamRouter
impl Send for StreamRouter
impl Sync for StreamRouter
impl Unpin for StreamRouter
impl UnsafeUnpin for StreamRouter
impl UnwindSafe for StreamRouter
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.