Struct ClientOptions
pub struct ClientOptions {
pub client_id: MqttString,
pub keep_alive: u16,
pub clean_start: bool,
pub username: Option<MqttString>,
pub password: Option<MqttBytesBuf>,
pub session_expiry: Option<u32>,
pub receive_maximum: Option<NonZeroU16>,
pub topic_alias_maximum: Option<u16>,
pub maximum_packet_size: Option<NonZeroU32>,
pub will: Option<WillOptions>,
pub reconnect: Option<ReconnectOptions>,
pub journal_path: Option<PathBuf>,
}Expand description
Options for the MQTT v5 client.
Controls the CONNECT packet fields, v5 session properties, and automatic reconnection behaviour.
Fields§
§client_id: MqttStringClient identifier. An empty string lets the broker assign one.
keep_alive: u16Keep-alive interval in seconds. 0 disables keep-alive.
clean_start: boolWhether to start a clean session.
username: Option<MqttString>Optional username for authentication.
password: Option<MqttBytesBuf>Optional password for authentication.
session_expiry: Option<u32>Session expiry interval in seconds (property 0x11).
None = not sent; Some(0) = session ends on disconnect.
receive_maximum: Option<NonZeroU16>Maximum number of in-flight QoS 1/2 messages this client can handle
(property 0x21).
topic_alias_maximum: Option<u16>Maximum topic alias value this client supports (property 0x22).
None or Some(0) = topic aliases disabled.
maximum_packet_size: Option<NonZeroU32>Maximum packet size this client is willing to accept (property 0x27).
None = no limit beyond protocol constraints.
will: Option<WillOptions>Will message configuration. None = no will message.
reconnect: Option<ReconnectOptions>Reconnect strategy. None disables automatic reconnection.
journal_path: Option<PathBuf>Path to a session journal file. When set, session state is persisted to this file so it can survive process restarts.
Implementations§
§impl ClientOptions
impl ClientOptions
pub const fn new(client_id: MqttString) -> Self
pub const fn new(client_id: MqttString) -> Self
Create minimal options with a client ID.
Defaults: keep-alive 60 s, clean start, no auth, no reconnect.
pub const fn keep_alive(self, secs: u16) -> Self
pub const fn keep_alive(self, secs: u16) -> Self
Set the keep-alive interval in seconds.
pub const fn clean_start(self, clean: bool) -> Self
pub const fn clean_start(self, clean: bool) -> Self
Set whether to start a clean session.
pub fn username(self, user: MqttString) -> Self
pub fn username(self, user: MqttString) -> Self
Set the username for authentication.
pub fn password(self, pass: MqttBytesBuf) -> Self
pub fn password(self, pass: MqttBytesBuf) -> Self
Set the password for authentication.
pub const fn session_expiry(self, seconds: u32) -> Self
pub const fn session_expiry(self, seconds: u32) -> Self
Set the session expiry interval in seconds (v5 property 0x11).
pub const fn receive_maximum(self, max: NonZeroU16) -> Self
pub const fn receive_maximum(self, max: NonZeroU16) -> Self
Set the receive maximum (v5 property 0x21).
pub const fn topic_alias_maximum(self, max: u16) -> Self
pub const fn topic_alias_maximum(self, max: u16) -> Self
Set the topic alias maximum this client supports (v5 property 0x22).
pub const fn maximum_packet_size(self, max: NonZeroU32) -> Self
pub const fn maximum_packet_size(self, max: NonZeroU32) -> Self
Set the maximum packet size this client will accept (v5 property
0x27).
pub fn will(self, topic: TopicBuf, payload: MqttBytesBuf) -> Self
pub fn will(self, topic: TopicBuf, payload: MqttBytesBuf) -> Self
Set a will message (Last Will and Testament).
The broker publishes this message if the client disconnects ungracefully.
pub fn will_with(self, will: WillOptions) -> Self
pub fn will_with(self, will: WillOptions) -> Self
Set a will message with full configuration.
pub fn reconnect(self) -> Self
pub fn reconnect(self) -> Self
Enable automatic reconnection with default settings.
pub const fn reconnect_with(self, opts: ReconnectOptions) -> Self
pub const fn reconnect_with(self, opts: ReconnectOptions) -> Self
Enable automatic reconnection with custom settings.
pub fn journal_path(self, path: impl Into<PathBuf>) -> Self
pub fn journal_path(self, path: impl Into<PathBuf>) -> Self
Set a session journal file path for durable session persistence.