Router

Struct Router 

Source
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: topic or topic: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

Source

pub fn new(routes: Vec<Route>) -> Self

Create a new router with the given routes

Source

pub async fn route( &self, resource_id: &str, payload: &[u8], ) -> Result<(), String>

Route a message to appropriate producer(s)

§Arguments
  • resource_id - Resource identifier (topic, path, segment name, etc.)
  • payload - Raw message payload bytes
§Returns
  • Ok(()) - At least one route successfully processed the message
  • Err(_) - All routes failed (or no routes found)
§Behavior
  • Checks all routes that match the resource_id (may be multiple)
  • Logs warnings on deserialization failures but continues
  • Logs debug message if no routes found for resource_id
Source

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).

Source

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 !UnwindSafe for Router

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.