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<NonZeroU16>,
pub topic_alias_maximum: Option<u16>,
pub maximum_packet_size: Option<NonZeroU32>,
pub connect_timeout: Option<Duration>,
pub ack_timeout: Option<Duration>,
pub will: Option<WillOptions>,
pub reconnect: Option<ReconnectOptions>,
}tokio only.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<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).
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§
§impl ClientOptions
impl ClientOptions
pub const fn new(client_id: MqttString) -> Self
pub const fn new(client_id: MqttString) -> Self
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.
pub const fn connect_timeout(self, timeout: Duration) -> Self
pub const fn connect_timeout(self, timeout: Duration) -> Self
Sets the connection-attempt deadline (TCP connect + CONNACK handshake).
pub const fn keep_alive(self, secs: u16) -> Self
pub const fn keep_alive(self, secs: u16) -> Self
Sets the keep-alive interval in seconds.
pub const fn ack_timeout(self, timeout: Duration) -> Self
pub const fn ack_timeout(self, timeout: Duration) -> Self
Sets the ack_timeout for in-flight QoS >= 1
operations.
pub const fn clean_start(self, clean_start: CleanStart) -> Self
pub const fn clean_start(self, clean_start: CleanStart) -> Self
Sets whether to request a clean start on the initial connect.
pub fn username(self, user: MqttString) -> Self
pub fn username(self, user: MqttString) -> Self
Sets the username for authentication.
pub fn password(self, pass: MqttBytesBuf) -> Self
pub fn password(self, pass: MqttBytesBuf) -> Self
Sets the password for authentication.
pub const fn session_expiry(self, seconds: u32) -> Self
pub const fn session_expiry(self, seconds: u32) -> Self
Sets 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
Sets 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
Sets 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
Sets 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
Sets 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
Sets a will message with full configuration.
pub fn reconnect(self) -> Self
pub fn reconnect(self) -> Self
Enables automatic reconnection with default settings.
pub const fn reconnect_with(self, opts: ReconnectOptions) -> Self
pub const fn reconnect_with(self, opts: ReconnectOptions) -> Self
Enables automatic reconnection with custom settings.
fn iter_connect_properties(&self) -> impl Iterator<Item = Property<'_>>
pub(crate) fn to_connect_properties( &self, ) -> Result<ConnectPropertiesBuf, PropertiesBufError>
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