pub struct ClientBuilder { /* private fields */ }
Expand description
A fluent builder interface to configure a Client.
Note that you must call .set_url()
or .set_url_string()
to
configure a host to connect to before you call .build()
.
To configure TLS options, pass an appropriate
rustls::ClientConfig
instance to
ClientBuilder.set_tls_client_config()
. Check out
rustls::ClientConfig.set_single_client_cert()
to set a TLS
client certificate and key, and rustls::ClientConfig.root_store
to set accepted CA roots for the server certificate. See the
example mqttc
in this repository for uses of all of these.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn set_url_string(&mut self, url: &str) -> Result<&mut Self>
pub fn set_url_string(&mut self, url: &str) -> Result<&mut Self>
Set the destination url for this mqtt connection to the given string (returning an error if the provided string is not a valid URL).
See Self::set_url for more details
Sourcepub fn set_url(&mut self, url: Url) -> Result<&mut Self>
pub fn set_url(&mut self, url: Url) -> Result<&mut Self>
Set the destination url for this mqtt connection.
Supported schema are:
- mqtt: An mqtt session over tcp (default TCP port 1883)
- mqtts: An mqtt session over tls (default TCP port 8883)
- ws: An mqtt session over a websocket (default TCP port 80, requires cargo feature “websocket”)
- wss: An mqtt session over a secure websocket (default TCP port 443, requires cargo feature “websocket”)
If the selected scheme is mqtts or wss, then it will preserve the previously provided tls configuration, if one has been given, or make a new default one otherwise.
Sourcepub fn set_username(&mut self, username: Option<String>) -> &mut Self
pub fn set_username(&mut self, username: Option<String>) -> &mut Self
Set username to authenticate with.
The default value is no username.
Sourcepub fn set_password(&mut self, password: Option<Vec<u8>>) -> &mut Self
pub fn set_password(&mut self, password: Option<Vec<u8>>) -> &mut Self
Set password to authenticate with.
The default is no password.
Sourcepub fn set_keep_alive(&mut self, keep_alive: KeepAlive) -> &mut Self
pub fn set_keep_alive(&mut self, keep_alive: KeepAlive) -> &mut Self
Set keep alive time.
This controls how often ping requests are sent when the connection is idle. See MQTT 3.1.1 specification section 3.1.2.10
The default value is 30 seconds.
Sourcepub fn set_tokio_runtime(&mut self, rt: TokioRuntime) -> &mut Self
pub fn set_tokio_runtime(&mut self, rt: TokioRuntime) -> &mut Self
Set the tokio runtime to spawn background tasks onto.
The default is to use the default tokio runtime, i.e. tokio::spawn()
.
Sourcepub fn set_client_id(&mut self, client_id: Option<String>) -> &mut Self
pub fn set_client_id(&mut self, client_id: Option<String>) -> &mut Self
Set the ClientId to connect with.
Sourcepub fn set_packet_buffer_len(&mut self, packet_buffer_len: usize) -> &mut Self
pub fn set_packet_buffer_len(&mut self, packet_buffer_len: usize) -> &mut Self
Set the inbound and outbound packet buffer length.
The default is 100.
Sourcepub fn set_max_packet_len(&mut self, max_packet_len: usize) -> &mut Self
pub fn set_max_packet_len(&mut self, max_packet_len: usize) -> &mut Self
Set the maximum packet length.
The default is 64 * 1024 bytes.
Sourcepub fn set_operation_timeout(
&mut self,
operation_timeout: Duration,
) -> &mut Self
pub fn set_operation_timeout( &mut self, operation_timeout: Duration, ) -> &mut Self
Set the timeout for operations.
The default is 20 seconds.
Sourcepub fn set_tls_client_config(
&mut self,
tls_client_config: ClientConfig,
) -> &mut Self
pub fn set_tls_client_config( &mut self, tls_client_config: ClientConfig, ) -> &mut Self
Set the TLS ClientConfig for the client-server connection.
Enables TLS. By default TLS is disabled.
Sourcepub fn set_connection_mode(&mut self, mode: ConnectionMode) -> &mut Self
pub fn set_connection_mode(&mut self, mode: ConnectionMode) -> &mut Self
Sets the connection mode to the given value
The default is to use Tcp
Sourcepub fn set_automatic_connect(&mut self, automatic_connect: bool) -> &mut Self
pub fn set_automatic_connect(&mut self, automatic_connect: bool) -> &mut Self
Set whether to automatically connect and reconnect.
The default is true.
Sourcepub fn set_connect_retry_delay(
&mut self,
connect_retry_delay: Duration,
) -> &mut Self
pub fn set_connect_retry_delay( &mut self, connect_retry_delay: Duration, ) -> &mut Self
Set the delay between connect retries.
The default is 30s.