API referencestd/mqtt

std/mqtt/broker

Public declarations, types, methods, and source contracts for std/mqtt/broker.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/mqtt/broker"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
bytes core/bytes broker.dodo
console std/console broker.dodo
hosted std/mqtt/hosted broker.dodo
io std/io broker.dodo
mqtt std/mqtt broker.dodo
native std/net/native broker.dodo
net std/net broker.dodo
operations std/net/operations broker.dodo

CLIENTS

Constant · Source

A small MQTT 3.1.1 broker for local networks, tests and learning. One thread serves up to CLIENTS connections with readiness polling. Subscriptions, retained messages and wills live in memory only, so nothing survives a restart. Server-side handlers see every message clients publish.

pub const CLIENTS: usize = 16

PACKET_BYTES

Constant · Source

Largest packet a client may send, which bounds every message.

pub const PACKET_BYTES: usize = 4096

RETAINED_BYTES

Constant · Source

pub const RETAINED_BYTES: usize = 16384

OUTBOX_BYTES

Constant · Source

pub const OUTBOX_BYTES: usize = 4096

ID_BYTES

Constant · Source

Per client: client ID, will topic plus payload, and subscription filters.

pub const ID_BYTES: usize = 128

WILL_BYTES

Constant · Source

pub const WILL_BYTES: usize = 512

FILTER_BYTES

Constant · Source

pub const FILTER_BYTES: usize = 1024

Config

Struct · Source

pub struct Config {
    // A new connection must send CONNECT within this time.
    pub connect_timeout_ms: u64
    // A client that cannot take a packet within this time is disconnected.
    pub write_timeout_ms: u64
    // Total accepted connections, not simultaneous ones. Zero is unlimited.
    pub max_connections: usize
    pub backlog: u32
}

Config.defaults

Function · Source

pub fn defaults() -> Config

Report

Struct · Source

pub struct Report {
    pub accepted: u64
    // Accepted CONNECTs, and those refused (protocol, client ID, credentials).
    pub connected: u64
    pub refused: u64
    // PUBLISH packets from clients, and copies sent to subscribers.
    pub messages: u64
    pub delivered: u64
    // Handler errors.
    pub failed: u64
    // Connections closed for invalid packets, timeouts or slow reading.
    pub dropped: u64
    pub cancelled: bool
    pub last_error: Option<mqtt.Error>
}

AllowAll

Struct · Source

Authenticators are values with allow(&mut self, client_id, username, password) -> bool. A refused client receives CONNACK NOT_AUTHORIZED.

pub struct AllowAll {

}

AllowAll.allow

Function · Source

pub fn allow(&mut self, client_id: &[u8], username: &[u8], password: &[u8]) -> bool

Password

Struct · Source

pub struct Password {
    // Private implementation fields omitted.
}

Password.allow

Function · Source

pub fn allow(&mut self, client_id: &[u8], username: &[u8], password: &[u8]) -> bool

print

Function · Source

Writes “topic payload” lines to standard output.

pub fn print() -> hosted.Print

Broker

Struct · Source

A built broker: run it, or test its handlers and authenticator directly.

pub struct Broker<R, A> {
    pub config: Config
    // Private implementation fields omitted.
}

Broker.publish

Function · Source

Runs every handler whose filter matches topic, without a network.

pub fn publish(&mut self, topic: &[u8], payload: &[u8]) -> mqtt.Delivery

Broker.allows

Function · Source

Whether the authenticator accepts these credentials.

pub fn allows(&mut self, client_id: &[u8], username: &[u8], password: &[u8]) -> bool

Broker.run

Function · Source

pub fn run(self, address: &[u8]) -> i32

Broker.serve

Function · Source

pub fn serve(self, address: &[u8]) -> Report!mqtt.Error

Broker.serve_until

Function · Source

pub fn serve_until<X>(self, address: &[u8], cancel: &X) -> Report!mqtt.Error

Builder

Struct · Source

pub struct Builder<R, A> {
    pub config: Config
    // Private implementation fields omitted.
}

Builder.on

Function · Source

Calls handler for every message a client publishes to a matching topic. Messages the handler puts in its outbox go to subscribers like any other.

pub fn on<H>(self, filter: &[u8], handler: H) -> Builder<mqtt.Routes<R, H>, A> from(self, filter, handler)

Builder.password

Function · Source

Accepts only clients that log in with this username and password.

pub fn password(self, username: &[u8], password: &[u8]) -> Builder<R, Password> from(self, username, password)

Builder.authenticate

Function · Source

Decides with auth.allow(client_id, username, password) -> bool.

pub fn authenticate<N>(self, auth: N) -> Builder<R, N> from(self, auth)

Builder.max_connections

Function · Source

Stops after this many connections have come and gone; 0 runs forever.

pub fn max_connections(self, count: usize) -> Builder<R, A> from(self)

Builder.build

Function · Source

pub fn build(self) -> Broker<R, A>!mqtt.RegistrationError from(self)

Builder.run

Function · Source

Listens on address, such as b“0.0.0.0:1883”, until the process stops. Prints failures and returns an exit code for main.

pub fn run(self, address: &[u8]) -> i32

Builder.serve

Function · Source

pub fn serve(self, address: &[u8]) -> Report!mqtt.RunError from(self)

Builder.serve_until

Function · Source

pub fn serve_until<X>(self, address: &[u8], cancel: &X) -> Report!mqtt.RunError from(self)

new

Function · Source

pub fn new() -> Builder<mqtt.NoRoutes, AllowAll> from(static)

Search every guide, reference page, and API declaration.