pub struct Router { /* private fields */ }Expand description
Generic message router for connector dispatch
Routes incoming messages to appropriate producers based on resource_id. Uses linear search which is efficient for <100 routes.
§Performance
- O(M) complexity where M = number of routes
- May check multiple routes if same resource_id maps to multiple types
- Typical routing time: <1μs for <50 routes
§Protocol Support
This router is protocol-agnostic. Each connector uses it with their own resource_id format:
- MQTT:
topic(e.g., “sensors/temperature”) - Kafka:
topicortopic:partition(e.g., “events” or “events:0”) - HTTP:
path(e.g., “/api/v1/sensors”) - DDS:
topic_name(e.g., “TelemetryData”) - Shmem:
segment_name(e.g., “temperature_buffer”)
Implementations§
Source§impl Router
impl Router
Sourcepub async fn route(
&self,
resource_id: &str,
payload: &[u8],
ctx: Option<&Arc<dyn Any + Send + Sync>>,
) -> Result<(), String>
pub async fn route( &self, resource_id: &str, payload: &[u8], ctx: Option<&Arc<dyn Any + Send + Sync>>, ) -> Result<(), String>
Route a message to appropriate producer(s)
§Arguments
resource_id- Resource identifier (topic, path, segment name, etc.)payload- Raw message payload bytesctx- Optional type-erased runtime context for context-aware deserializers
§Returns
Ok(())- Always returns Ok, even if no routes matched or processing failed. Failures are logged (via tracing/defmt) but do not propagate as errors.
§Behavior
- Checks all routes that match the resource_id (may be multiple)
- For
DeserializerKind::Raw, calls the deserializer with payload only - For
DeserializerKind::Context, calls with context + payload (skips if no context) - Logs warnings on deserialization failures but continues
- Logs debug message if no routes found for resource_id
Sourcepub fn resource_ids(&self) -> Vec<Arc<str>>
pub fn resource_ids(&self) -> Vec<Arc<str>>
Get list of all resource IDs registered in this router
Useful for subscribing at the protocol level (e.g., MQTT SUBSCRIBE). Returns unique resource IDs (deduplicated even if multiple routes per resource).
Sourcepub fn route_count(&self) -> usize
pub fn route_count(&self) -> usize
Get the number of routes in this router
Auto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl UnsafeUnpin for Router
impl !UnwindSafe for Router
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
Mutably borrows from an owned value. Read more