Struct ClientBuilder
pub struct ClientBuilder<T> {
transport: T,
options: ClientOptions,
persistence: SessionPersistence,
command_channel_capacity: usize,
message_channel_capacity: usize,
}Expand description
Builder for an MqttClient.
Obtain one with MqttClient::builder, set the persistence
backend and channel capacities, then call
start:
use finmqtt_client::tokio::{ClientOptions, FilePersistence, MqttClient, TcpTransport};
let (owner, client, messages) = MqttClient::builder(
TcpTransport::new("broker.example.com", 1883),
ClientOptions::new("my-client".parse().unwrap()).reconnect(),
)
.persistence(FilePersistence::new("session.journal"))
.command_channel_capacity(512)
.start()
.await?;Fields§
§transport: T§options: ClientOptions§persistence: SessionPersistence§command_channel_capacity: usize§message_channel_capacity: usizeImplementations§
Source§impl<T> ClientBuilder<T>
impl<T> ClientBuilder<T>
Sourcepub fn persistence<P>(self, persistence: P) -> ClientBuilder<T>where
P: Into<SessionPersistence>,
pub fn persistence<P>(self, persistence: P) -> ClientBuilder<T>where
P: Into<SessionPersistence>,
Sets how the session is durably persisted across restarts.
Pass a backend builder:
FilePersistence for
a journal file, or TursoPersistence
(with the turso feature) for a turso database. Defaults to no
persistence.
Sourcepub const fn command_channel_capacity(self, capacity: usize) -> ClientBuilder<T>
pub const fn command_channel_capacity(self, capacity: usize) -> ClientBuilder<T>
Sets the command channel capacity (default
DEFAULT_COMMAND_CHANNEL_CAPACITY).
Bounds how many publish/subscribe/unsubscribe commands may be queued before callers must await; raising it trades memory for burst tolerance.
Sourcepub const fn message_channel_capacity(self, capacity: usize) -> ClientBuilder<T>
pub const fn message_channel_capacity(self, capacity: usize) -> ClientBuilder<T>
Sets the inbound message channel capacity (default
DEFAULT_MESSAGE_CHANNEL_CAPACITY).
Bounds how many received messages buffer for the MessageStream
before backpressure pauses inbound reads.
Sourcepub async fn start(
self,
) -> Result<(EventLoopHandle, MqttClient, MessageStream), Error>
pub async fn start( self, ) -> Result<(EventLoopHandle, MqttClient, MessageStream), Error>
Starts the client, loading any persisted session first.
Returns the EventLoopHandle that owns the spawned event loop, the
client handle, and the MessageStream of incoming PUBLISH messages.
The event loop runs as long as the EventLoopHandle lives; keep it
and call stop for a graceful shutdown. This
method returns immediately; the first connection attempt happens in
the background.
To block until the broker accepted the connection, await
connection_status(). wait_until_connected()
on the returned client.
§Errors
Returns an I/O error if the persistence backend cannot be opened or its persisted state cannot be loaded.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for ClientBuilder<T>
impl<T> !UnwindSafe for ClientBuilder<T>
impl<T> Freeze for ClientBuilder<T>where
T: Freeze,
impl<T> Send for ClientBuilder<T>where
T: Send,
impl<T> Sync for ClientBuilder<T>where
T: Sync,
impl<T> Unpin for ClientBuilder<T>where
T: Unpin,
impl<T> UnsafeUnpin for ClientBuilder<T>where
T: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more