Struct ClientBuilder

Source
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

Source

pub fn build(&mut self) -> Result<Client>

Build a new Client with this configuration.

Source

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

Source

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.

Source

pub fn set_username(&mut self, username: Option<String>) -> &mut Self

Set username to authenticate with.

The default value is no username.

Source

pub fn set_password(&mut self, password: Option<Vec<u8>>) -> &mut Self

Set password to authenticate with.

The default is no password.

Source

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.

Source

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().

Source

pub fn set_client_id(&mut self, client_id: Option<String>) -> &mut Self

Set the ClientId to connect with.

Source

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.

Source

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.

Source

pub fn set_operation_timeout( &mut self, operation_timeout: Duration, ) -> &mut Self

Set the timeout for operations.

The default is 20 seconds.

Source

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.

Source

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

Source

pub fn set_automatic_connect(&mut self, automatic_connect: bool) -> &mut Self

Set whether to automatically connect and reconnect.

The default is true.

Source

pub fn set_connect_retry_delay( &mut self, connect_retry_delay: Duration, ) -> &mut Self

Set the delay between connect retries.

The default is 30s.

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> ClientBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.