Rust

adapter

Module

The interfaces a broker runs on: an Adapter serves connections and calls the server's hooks, and its Timer reaps connections that go silent.

Contents

use utopia_mqtt::Adapter;
Rust
pub trait Adapter: Outbound + Clone + 'static

An MQTT transport: Tokio on the network, Memory in process. Server drives one.

An adapter delivers whole MQTT packets, one per call of the receive hook, however its carrier frames them. Adapters are cheap handles (clones share one server); each on_* method replaces the hook set before.

Implemented byMemoryTokio
use utopia_mqtt::Outbound;
Rust
pub trait Outbound: Send + Sync

The way back to the clients: write bytes to a connection, or close it. Every Adapter is one; a Connection keeps one to deliver.

Implemented byArcMemoryTokio
use utopia_mqtt::Timer;
Rust
pub trait Timer: Send + Sync

Keep-alive deadlines by connection: a connection scheduled with a keep-alive interval is reaped (the tick hook gets its id) once it has been silent for longer than the interval allows.

Implemented byNoTimerTimingWheel
Rust
pub type ConnectionHook = Arc<dyn Fn(i64) -> Result<(), Error> + Send + Sync>

Called with a connection id when it opens or closes.

Rust
pub type ReceiveHook = Arc<dyn Fn(i64, &[u8]) -> Result<(), Error> + Send + Sync>

Called with a connection id and one whole MQTT packet it sent.

Rust
pub type StartHook = Arc<dyn Fn() + Send + Sync>

Called once the adapter is listening.

Rust
pub type TimerHook = Arc<dyn Fn(i64) + Send + Sync>

Called with the id a Timer reaps or clears.

Rust
pub type WorkerHook = Arc<dyn Fn(i64) + Send + Sync>

Called with each worker id as its worker starts.