pub struct MqttConfig { /* private fields */ }Expand description
Connection settings for an MqttTransport.
Construct with MqttConfig::new and refine with the chained setters; every
field has a sensible default so only the broker address and client id are
required.
Implementations§
Source§impl MqttConfig
impl MqttConfig
Sourcepub fn new(
client_id: impl Into<String>,
host: impl Into<String>,
port: u16,
) -> Self
pub fn new( client_id: impl Into<String>, host: impl Into<String>, port: u16, ) -> Self
Creates a configuration for the given client id and broker address.
§Arguments
client_id- the MQTT client identifier presented to the broker.host- the broker hostname or IP address.port- the broker TCP port, conventionally1883for plaintext MQTT.
§Returns
A configuration with a 30-second keep-alive, a request capacity of 64, a
default quality of service of QualityOfService::AtLeastOnce, and a
packet limit of DEFAULT_MAX_PACKET_SIZE.
Sourcepub fn credentials(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Signs in to the broker with a username and password.
The password travels in the clear unless the connection uses TLS, so a broker reached over a network worth protecting wants both.
§Arguments
username- the name the broker knows the client by.password- its password.
§Returns
The updated configuration, for chaining.
Sourcepub fn username(&self) -> Option<&str>
pub fn username(&self) -> Option<&str>
Returns the username the client signs in with.
§Returns
The username, or None for a client that does not sign in.
Sourcepub fn max_packet_size(self, bytes: usize) -> Self
pub fn max_packet_size(self, bytes: usize) -> Self
Sets the largest packet the connection sends or accepts, in bytes.
A packet is a message’s topic and payload plus a few bytes of framing. A send whose packet would be larger is refused and the connection stays up, but a larger packet arriving from the broker ends the connection, so every client that shares a topic needs a limit that fits it. MQTT itself allows a packet of up to 268,435,455 bytes after its fixed header.
§Arguments
bytes- the limit, which applies to both directions.
§Returns
The updated configuration, for chaining.
Sourcepub fn keep_alive(self, interval: Duration) -> Self
pub fn keep_alive(self, interval: Duration) -> Self
Trait Implementations§
Source§impl Clone for MqttConfig
impl Clone for MqttConfig
Source§fn clone(&self) -> MqttConfig
fn clone(&self) -> MqttConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more