Struct ClientOptions
#[non_exhaustive]pub struct ClientOptions {Show 13 fields
pub client_id: MqttString,
pub keep_alive: u16,
pub clean_start: CleanStart,
pub username: Option<MqttString>,
pub password: Option<MqttBytesBuf>,
pub session_expiry: Option<u32>,
pub receive_maximum: Option<NonZero<u16>>,
pub topic_alias_maximum: Option<u16>,
pub maximum_packet_size: Option<NonZero<u32>>,
pub connect_timeout: Option<Duration>,
pub ack_timeout: Option<Duration>,
pub will: Option<WillOptions>,
pub reconnect: Option<ReconnectOptions>,
}Expand description
Options for the MQTT v5 client.
Controls the CONNECT packet fields, v5 session properties, and automatic reconnection behaviour.
Construct it with ClientOptions::new and the builder methods.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.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: CleanStartWhether to request a clean start on the initial connect.
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<NonZero<u16>>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<NonZero<u32>>Maximum packet size this client is willing to accept (property 0x27).
The client advertises this value to the broker and enforces it on
receive. It rejects an inbound packet whose declared size exceeds this
with DISCONNECT (PacketTooLarge) before it buffers the body. A peer
cannot force an unbounded allocation. Defaults to
DEFAULT_MAX_PACKET_SIZE. Raise it for large-payload workloads.
connect_timeout: Option<Duration>Deadline for one connection attempt: TCP connect plus the CONNECT
/ CONNACK handshake. If it elapses the attempt is abandoned (and
retried when reconnection is enabled), so a broker that accepts the
socket but never answers cannot hang the client. None disables it.
ack_timeout: Option<Duration>Deadline for an in-flight QoS >= 1 operation to be acknowledged. If a
PUBACK/PUBCOMP (publish) or SUBACK/UNSUBACK (subscribe/unsubscribe) does
not arrive within this duration of the packet being written, the
connection is treated as dead and torn down; reconnection then resumes
the session and retransmits the unacknowledged operations.
This is a liveness signal tied to real traffic, independent of
keep_alive: it detects a broker that keeps the
socket alive (and may even send unrelated inbound traffic) but never
acknowledges your operations, which the keep-alive probe cannot.
It only provides coverage while operations are in flight. With no
outstanding QoS >= 1 operation there is nothing to time out, so an
idle gap is not covered. Setting keep_alive to 0 and relying solely
on this is safe only under a workload with continuous
QoS >= 1 traffic. Defaults to DEFAULT_ACK_TIMEOUT; None
disables it.
will: Option<WillOptions>Will message configuration. None = no will message.
reconnect: Option<ReconnectOptions>Reconnect strategy. None disables automatic reconnection.
Implementations§
Source§impl ClientOptions
impl ClientOptions
Sourcepub const fn new(client_id: MqttString) -> ClientOptions
pub const fn new(client_id: MqttString) -> ClientOptions
Creates minimal options with a client ID.
Defaults: keep-alive 60 s and CleanStart::Auto. Authentication and
reconnection are off. The size limit for inbound packets is
DEFAULT_MAX_PACKET_SIZE, the handshake deadline is
DEFAULT_CONNECT_TIMEOUT and the ack deadline is
DEFAULT_ACK_TIMEOUT.
Sourcepub const fn connect_timeout(self, timeout: Duration) -> ClientOptions
pub const fn connect_timeout(self, timeout: Duration) -> ClientOptions
Sets the connection-attempt deadline (TCP connect + CONNACK handshake).
Sourcepub const fn keep_alive(self, secs: u16) -> ClientOptions
pub const fn keep_alive(self, secs: u16) -> ClientOptions
Sets the keep-alive interval in seconds.
Sourcepub const fn ack_timeout(self, timeout: Duration) -> ClientOptions
pub const fn ack_timeout(self, timeout: Duration) -> ClientOptions
Sets the ack_timeout for in-flight QoS >= 1
operations.
Sourcepub const fn clean_start(self, clean_start: CleanStart) -> ClientOptions
pub const fn clean_start(self, clean_start: CleanStart) -> ClientOptions
Sets whether to request a clean start on the initial connect.
Sourcepub fn username(self, user: MqttString) -> ClientOptions
pub fn username(self, user: MqttString) -> ClientOptions
Sets the username for authentication.
Sourcepub fn password(self, pass: MqttBytesBuf) -> ClientOptions
pub fn password(self, pass: MqttBytesBuf) -> ClientOptions
Sets the password for authentication.
Sourcepub const fn session_expiry(self, seconds: u32) -> ClientOptions
pub const fn session_expiry(self, seconds: u32) -> ClientOptions
Sets the session expiry interval in seconds (v5 property 0x11).
Sourcepub const fn receive_maximum(self, max: NonZero<u16>) -> ClientOptions
pub const fn receive_maximum(self, max: NonZero<u16>) -> ClientOptions
Sets the receive maximum (v5 property 0x21).
Sourcepub const fn topic_alias_maximum(self, max: u16) -> ClientOptions
pub const fn topic_alias_maximum(self, max: u16) -> ClientOptions
Sets the topic alias maximum this client supports (v5 property 0x22).
Sourcepub const fn maximum_packet_size(self, max: NonZero<u32>) -> ClientOptions
pub const fn maximum_packet_size(self, max: NonZero<u32>) -> ClientOptions
Sets the maximum packet size this client will accept (v5 property
0x27).
Sourcepub fn will(self, topic: TopicBuf, payload: MqttBytesBuf) -> ClientOptions
pub fn will(self, topic: TopicBuf, payload: MqttBytesBuf) -> ClientOptions
Sets a will message (Last Will and Testament).
The broker publishes this message if the client disconnects ungracefully.
Sourcepub fn will_with(self, will: WillOptions) -> ClientOptions
pub fn will_with(self, will: WillOptions) -> ClientOptions
Sets a will message with full configuration.
Sourcepub fn reconnect(self) -> ClientOptions
pub fn reconnect(self) -> ClientOptions
Enables automatic reconnection with default settings.
Sourcepub const fn reconnect_with(self, opts: ReconnectOptions) -> ClientOptions
pub const fn reconnect_with(self, opts: ReconnectOptions) -> ClientOptions
Enables automatic reconnection with custom settings.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ClientOptions
impl RefUnwindSafe for ClientOptions
impl Send for ClientOptions
impl Sync for ClientOptions
impl Unpin for ClientOptions
impl UnsafeUnpin for ClientOptions
impl UnwindSafe for ClientOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more