API referencestd/mqtt

std/mqtt/app

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

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/app"

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
console std/console app.dodo
hosted std/mqtt/hosted app.dodo
mqtt std/mqtt app.dodo
native std/net/native app.dodo
net std/net app.dodo
thread std/thread app.dodo

OUTBOX_BYTES

Constant · Source

A long-running MQTT client: subscribe handlers to topic filters, add periodic tasks, and run. The app connects, subscribes, calls every handler whose filter matches a message, publishes what handlers put in their outbox, keeps the connection alive, and reconnects after it drops.

pub const OUTBOX_BYTES: usize = 4096

print

Function · Source

Writes “topic payload” lines to standard output.

pub fn print() -> hosted.Print

NoTasks

Struct · Source

Periodic tasks. A task is a value with tick(&mut self, outbox: &mut mqtt.Outbox) -> void!mqtt.Error; it runs once right after each connection and then every interval while connected.

pub struct NoTasks {

}

NoTasks.start

Function · Source

pub fn start(&mut self, now: u64)

NoTasks.run_due

Function · Source

pub fn run_due(&mut self, now: u64, everything: bool, outbox: &mut mqtt.Outbox, outcome: &mut mqtt.Dispatch)

NoTasks.next_due

Function · Source

pub fn next_due(&self) -> u64

NoTasks.len

Function · Source

pub fn len(&self) -> usize

Tasks

Struct · Source

pub struct Tasks<A, T> {
    // Private implementation fields omitted.
}

Tasks.start

Function · Source

pub fn start(&mut self, now: u64)

Tasks.run_due

Function · Source

pub fn run_due(&mut self, now: u64, everything: bool, outbox: &mut mqtt.Outbox, outcome: &mut mqtt.Dispatch)

Tasks.next_due

Function · Source

pub fn next_due(&self) -> u64

Tasks.len

Function · Source

pub fn len(&self) -> usize

Report

Struct · Source

pub struct Report {
    // Successful connections, including the first.
    pub connections: u64
    pub received: u64
    pub published: u64
    // Handler and task errors. The message still counts as handled.
    pub failed: u64
    pub reconnects: u64
    pub cancelled: bool
    pub last_error: Option<mqtt.Error>
}

App

Struct · Source

A built app: run it, or test its handlers and tasks without a broker.

pub struct App<R, T> {
    // Private implementation fields omitted.
}

App.deliver

Function · Source

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

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

App.tick

Function · Source

Runs every periodic task once, without a broker.

pub fn tick(&mut self) -> mqtt.Delivery

App.run

Function · Source

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

App.serve

Function · Source

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

App.serve_until

Function · Source

Runs until cancel.cancelled() returns true, or max_messages arrive. Fails only if the first connection fails or the broker refuses the client or a subscription; later connection losses reconnect.

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

Builder

Struct · Source

pub struct Builder<R, T> {
    // Private implementation fields omitted.
}

Builder.on

Function · Source

Calls handler for every message whose topic matches filter. A handler is a value with handle(&mut self, message: &mqtt.Message, outbox: &mut mqtt.Outbox) -> void!mqtt.Error.

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

Builder.every

Function · Source

Calls task.tick(outbox) right after connecting, then every milliseconds.

pub fn every<N>(self, milliseconds: u64, task: N) -> Builder<R, Tasks<T, N>> from(self, task)

Builder.login

Function · Source

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

Builder.will

Function · Source

Message the broker publishes if this app disappears without disconnecting.

pub fn will(self, topic: &[u8], payload: &[u8]) -> Builder<R, T> from(self, topic, payload)

Builder.status

Function · Source

Keeps a retained “online” or “offline” at topic, so others can see whether this app is running, even after a crash.

pub fn status(self, topic: &[u8]) -> Builder<R, T> from(self, topic)

Builder.keep_alive

Function · Source

pub fn keep_alive(self, seconds: u16) -> Builder<R, T> from(self)

Builder.qos

Function · Source

Subscription quality of service; AtLeastOnce by default.

pub fn qos(self, qos: mqtt.QoS) -> Builder<R, T> from(self)

Builder.max_messages

Function · Source

Disconnects after this many messages; 0, the default, runs forever.

pub fn max_messages(self, count: u64) -> Builder<R, T> from(self)

Builder.build

Function · Source

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

Builder.run

Function · Source

Connects to url (mqtt://host[:port]) and runs until the process stops. Prints failures and returns an exit code for main.

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

Builder.serve

Function · Source

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

Builder.serve_until

Function · Source

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

new

Function · Source

Starts an app that connects as client_id.

pub fn new(client_id: &[u8]) -> Builder<mqtt.NoRoutes, NoTasks> from(client_id)

Search every guide, reference page, and API declaration.