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_tokio::transport::TcpTransport;
use finmqtt_tokio::{ClientOptions, FilePersistence, MqttClient};
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§
§impl<T: Transport + Send + Sync + 'static> ClientBuilder<T>
impl<T: Transport + Send + Sync + 'static> ClientBuilder<T>
pub(crate) const fn new(transport: T, options: ClientOptions) -> Self
pub(crate) const fn new(transport: T, options: ClientOptions) -> Self
Creates a builder with default wiring and no persistence.
pub fn persistence(self, persistence: impl Into<SessionPersistence>) -> Self
pub fn persistence(self, persistence: impl Into<SessionPersistence>) -> Self
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.
pub const fn command_channel_capacity(self, capacity: usize) -> Self
pub const fn command_channel_capacity(self, capacity: usize) -> Self
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.
pub const fn message_channel_capacity(self, capacity: usize) -> Self
pub const fn message_channel_capacity(self, capacity: usize) -> Self
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.
pub async fn start(self) -> Result<(EventLoopHandle, MqttClient, MessageStream)>
pub async fn start(self) -> Result<(EventLoopHandle, MqttClient, MessageStream)>
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.
Auto Trait Implementations§
impl<T> Freeze for ClientBuilder<T>where
T: Freeze,
impl<T> !RefUnwindSafe for ClientBuilder<T>
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> !UnwindSafe for ClientBuilder<T>
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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