pub struct ConnectionOptions {
pub client_id: String,
pub host: String,
pub port: u16,
pub keep_alive: Duration,
pub credentials: Option<Credentials>,
pub session: SessionPolicy,
pub protocol: ProtocolVersion,
pub transport: Transport,
/* private fields */
}Expand description
Protocol-neutral MQTT connection options.
Covers the settings most applications need. Backend-specific knobs that
are intentionally not mirrored here (inflight window, request channel
sizes, pending throttle, packet-size caps, proxies, …) are reachable via
ConnectionOptions::backend_tweak behind the unstable-backend-api
feature.
Fields§
§client_id: StringMQTT client identifier. May be empty only with
SessionPolicy::CleanPerConnection.
host: StringBroker host name or IP address — except under
Transport::Ws/Transport::Wss, where it must be the full URL of
the WebSocket endpoint: ws://host:port/path for
Transport::Ws and wss://host:port/path for Transport::Wss.
The scheme must match the variant. Writing ws:// alongside
Transport::Wss silently produces an unencrypted connection on the
default backend — see the warning on Transport.
port: u16Broker port
keep_alive: DurationKeep-alive interval. Duration::ZERO disables keep-alive; non-zero
values must be at least one second.
credentials: Option<Credentials>Optional username/password
session: SessionPolicySession persistence policy
protocol: ProtocolVersionProtocol version to speak on the wire (MQTT 3.1.1 or MQTT 5)
transport: TransportNetwork transport
Implementations§
Source§impl ConnectionOptions
impl ConnectionOptions
Sourcepub fn new(
client_id: impl Into<String>,
host: impl Into<String>,
port: u16,
) -> ConnectionOptions
pub fn new( client_id: impl Into<String>, host: impl Into<String>, port: u16, ) -> ConnectionOptions
Create options with defaults: TCP transport, 60 s keep-alive,
SessionPolicy::CleanPerConnection, MQTT 3.1.1.
Sourcepub fn from_url(url: &str) -> Result<ConnectionOptions, UrlParseError>
pub fn from_url(url: &str) -> Result<ConnectionOptions, UrlParseError>
Parse connection options from an MQTT URL.
Grammar (compatible with rumqttc’s URL grammar where mirrored):
- schemes:
tcp/mqtt(port 1883),ssl/mqtts(8883),ws/wss(8000 — rumqttc-compat quirk). All schemes parse regardless of compiled features; transport availability is checked at connect.
The ws/wss schemes parse but do not yield a working configuration
— only the host survives (url.host_str()), while a WebSocket connection
needs the whole URL in host (see Transport). Build
WebSocket options by hand until the connection target stops being three
separate fields; tracked in docs/ROADMAP.md.
- userinfo:
mqtt://user:pass@hostsets credentials. - query:
client_id(required),keep_alive_secs,clean_session(true→SessionPolicy::CleanPerConnection,false→SessionPolicy::Resume),protocol(4or5).
Backend-tuning parameters accepted by rumqttc URLs (inflight_num,
request_channel_capacity_num, max_request_batch_num,
pending_throttle_usecs, max_incoming_packet_size_bytes,
max_outgoing_packet_size_bytes) are intentionally NOT supported —
they error with a pointer to the unstable-backend-api escape hatch.
Unknown parameters are an error.
Sourcepub fn backend_tweak(
&mut self,
f: impl Fn(&mut BackendOptions<'_>) + Send + Sync + 'static,
) -> &mut ConnectionOptions
pub fn backend_tweak( &mut self, f: impl Fn(&mut BackendOptions<'_>) + Send + Sync + 'static, ) -> &mut ConnectionOptions
Register a semver-exempt tweak applied to the raw backend options at connect time, after the facade conversion, in insertion order.
This is the escape hatch for backend knobs the facade does not mirror.
Its signature may change with ANY backend change — it is exempt from
this crate’s semver guarantees. The backend crate itself is
re-exported as mqtt_typed_client_core::backend::unstable::rumqttc so you
don’t need a version-matched dependency of your own.
Trait Implementations§
Source§impl Clone for ConnectionOptions
impl Clone for ConnectionOptions
Source§fn clone(&self) -> ConnectionOptions
fn clone(&self) -> ConnectionOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more