Struct paho_mqtt::create_options::CreateOptionsBuilder
source · pub struct CreateOptionsBuilder { /* private fields */ }
Expand description
Builder to construct client creation options.
Examples
use paho_mqtt as mqtt;
let opts = mqtt::CreateOptionsBuilder::new()
.server_uri("tcp://localhost:1883")
.client_id("client1")
.finalize();
let cli = mqtt::AsyncClient::new(opts).unwrap();
Implementations§
source§impl CreateOptionsBuilder
impl CreateOptionsBuilder
sourcepub fn new_v3() -> Self
pub fn new_v3() -> Self
Constructs a builder for a client that can only connect using MQTT v3.x.
sourcepub fn server_uri<S>(self, server_uri: S) -> Selfwhere
S: Into<String>,
pub fn server_uri<S>(self, server_uri: S) -> Selfwhere S: Into<String>,
Sets the the URI to the MQTT broker. Alternately, the application can specify multiple servers via the connect options.
Arguments
server_uri
The URI string to specify the server in the form
protocol://host:port, where the protocol can be
tcp or ssl, and the host can be an IP address
or domain name.
sourcepub fn client_id<S>(self, client_id: S) -> Selfwhere
S: Into<String>,
pub fn client_id<S>(self, client_id: S) -> Selfwhere S: Into<String>,
Sets the client identifier string that is sent to the server. The client ID is a unique name to identify the client to the server, which can be used if the client desires the server to hold state about the session. If the client requests a clean session, this can be an empty string, in which case the server will assign a random name for the client.
The broker is required to honor a client ID of up to 23 bytes, but could honor longer ones, depending on the broker.
Note that if this is an empty string, the clean session parameter must be set to true.
Arguments
client_id
A UTF-8 string identifying the client to the server.
sourcepub fn persistence<P>(self, persist: P) -> Selfwhere
P: Into<PersistenceType>,
pub fn persistence<P>(self, persist: P) -> Selfwhere P: Into<PersistenceType>,
Sets the type of persistence used by the client.
The default is for the library to automatically use file persistence,
although this can be turned off by specify None
for a more
performant, though possibly less reliable system.
Arguments
persist
The type of persistence to use.
sourcepub fn user_persistence<T>(self, persistence: T) -> Selfwhere
T: ClientPersistence + Send + 'static,
pub fn user_persistence<T>(self, persistence: T) -> Selfwhere T: ClientPersistence + Send + 'static,
Sets a user-defined persistence store.
This sets the persistence to use a custom one defined by the
application. This can be anything that implements the
ClientPersistence
trait.
Arguments
persist
An application-defined custom persistence store.
sourcepub fn max_buffered_messages(self, n: i32) -> Self
pub fn max_buffered_messages(self, n: i32) -> Self
Sets the maximum number of messages that can be buffered for delivery.
When the client is off-line, this specifies the maximum number of messages that can be buffered. Even while connected, the library needs a small buffer to queue outbound messages. Setting it to zero disables off-line buffering but still keeps some slots open for on-line operation.
Arguments
n
The maximum number of messages that can be buffered. Setting this
to zero also disables any off-line buffering.
sourcepub fn send_while_disconnected(self, on: bool) -> Self
pub fn send_while_disconnected(self, on: bool) -> Self
Allow the application to send (publish) messages while disconnected.
If this is disabled, then any time the app tries to publish while
disconnected results in a “disconnected” error from the client.
When enabled, the application can queue up to
max_buffered_messages()
while off-line.
Arguments
on
Whether to allow off-line buffering in the client.
sourcepub fn mqtt_version(self, ver: u32) -> Self
pub fn mqtt_version(self, ver: u32) -> Self
Sets the version of MQTT to use on the connect.
Arguments
ver
The version of MQTT to use when connecting to the broker.
* (0) try the latest version (3.1.1) and work backwards
* (3) only try v3.1
* (4) only try v3.1.1
* (5) only try v5
sourcepub fn allow_disconnected_send_at_anytime(self, allow: bool) -> Self
pub fn allow_disconnected_send_at_anytime(self, allow: bool) -> Self
Allow sending of messages while disconnected before a first successful connect.
sourcepub fn delete_oldest_messages(self, delete_oldest: bool) -> Self
pub fn delete_oldest_messages(self, delete_oldest: bool) -> Self
When the maximum number of buffered messages is reached, delete the oldest rather than the newest.
sourcepub fn restore_messages(self, restore: bool) -> Self
pub fn restore_messages(self, restore: bool) -> Self
If set, messages from persistence are restored on create. Defaults to true.
sourcepub fn persist_qos0(self, persist: bool) -> Self
pub fn persist_qos0(self, persist: bool) -> Self
If set, QoS0 publish commands are persisted. Defaults to true.
sourcepub fn user_data(self, data: UserData) -> Self
pub fn user_data(self, data: UserData) -> Self
Sets the user-defined data structure for the client.
sourcepub fn finalize(self) -> CreateOptions
pub fn finalize(self) -> CreateOptions
Constructs a set of create options from the builder information.
sourcepub fn create_client(self) -> Result<AsyncClient>
pub fn create_client(self) -> Result<AsyncClient>
Finalize the builder and create an asynchronous client.