pub struct MqttServer<St, C, Cn, P, M = Identity> { /* private fields */ }
Expand description
Mqtt Server
Implementations§
source§impl<St, C> MqttServer<St, C, DefaultControlService<St, C::Error>, DefaultPublishService<St, C::Error>, InFlightService>
impl<St, C> MqttServer<St, C, DefaultControlService<St, C::Error>, DefaultPublishService<St, C::Error>, InFlightService>
sourcepub fn new<F>(handshake: F) -> Selfwhere
F: IntoServiceFactory<C, Handshake>,
pub fn new<F>(handshake: F) -> Selfwhere
F: IntoServiceFactory<C, Handshake>,
Create server factory and provide handshake service
source§impl<St, C, Cn, P> MqttServer<St, C, Cn, P, InFlightService>
impl<St, C, Cn, P> MqttServer<St, C, Cn, P, InFlightService>
sourcepub fn max_receive_size(self, val: usize) -> Self
pub fn max_receive_size(self, val: usize) -> Self
Total size of received in-flight messages.
By default total in-flight size is set to 64Kb
source§impl<St, C, Cn, P, M> MqttServer<St, C, Cn, P, M>where
St: 'static,
C: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static,
C::Error: Debug,
Cn: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
P: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
impl<St, C, Cn, P, M> MqttServer<St, C, Cn, P, M>where
St: 'static,
C: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static,
C::Error: Debug,
Cn: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
P: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
sourcepub fn connect_timeout(self, timeout: Seconds) -> Self
pub fn connect_timeout(self, timeout: Seconds) -> Self
Set client timeout for first Connect
frame.
Defines a timeout for reading Connect
frame. If a client does not transmit
the entire frame within this time, the connection is terminated with
Mqtt::Handshake(HandshakeError::Timeout) error.
By default, connect timeout is disabled.
sourcepub fn disconnect_timeout(self, val: Seconds) -> Self
pub fn disconnect_timeout(self, val: Seconds) -> Self
Set server connection disconnect timeout.
Defines a timeout for disconnect connection. If a disconnect procedure does not complete within this time, the connection get dropped.
To disable timeout set value to 0.
By default disconnect timeout is set to 3 seconds.
sourcepub fn frame_read_rate(
self,
timeout: Seconds,
max_timeout: Seconds,
rate: u16,
) -> Self
pub fn frame_read_rate( self, timeout: Seconds, max_timeout: Seconds, rate: u16, ) -> Self
Set read rate parameters for single frame.
Set read timeout, max timeout and rate for reading payload. If the client
sends rate
amount of data within timeout
period of time, extend timeout by timeout
seconds.
But no more than max_timeout
timeout.
By default frame read rate is disabled.
sourcepub fn max_size(self, size: u32) -> Self
pub fn max_size(self, size: u32) -> Self
Set max inbound frame size.
If max size is set to 0
, size is unlimited.
By default max size is set to 0
sourcepub fn max_receive(self, val: u16) -> Self
pub fn max_receive(self, val: u16) -> Self
Set receive max
Number of in-flight publish packets. By default receive max is set to 15 packets. To disable timeout set value to 0.
sourcepub fn max_topic_alias(self, val: u16) -> Self
pub fn max_topic_alias(self, val: u16) -> Self
Number of topic aliases.
By default value is set to 32
sourcepub fn max_qos(self, qos: QoS) -> Self
pub fn max_qos(self, qos: QoS) -> Self
Set server max qos setting.
By default max qos is not set.
sourcepub fn handle_qos_after_disconnect(self, max_qos: Option<QoS>) -> Self
pub fn handle_qos_after_disconnect(self, max_qos: Option<QoS>) -> Self
Handle max received QoS messages after client disconnect.
By default, messages received before dispatched to the publish service will be dropped if the client disconnect immediately.
If this option is set to Some(QoS::AtMostOnce)
, only the QoS 0 messages received will
always be handled by the server’s publish service no matter if the client is disconnected
or not.
If this option is set to Some(QoS::AtLeastOnce)
, only the QoS 0 and QoS 1 messages
received will always be handled by the server’s publish service no matter if the client
is disconnected or not. The QoS 2 messages will be dropped if the client is disconnected
before the server dispatches them to the publish service.
If this option is set to Some(QoS::ExactlyOnce)
, all the messages received will always
be handled by the server’s publish service no matter if the client is disconnected or not.
By default handle-qos-after-disconnect is set to None
sourcepub fn reset_middlewares(self) -> MqttServer<St, C, Cn, P, Identity>
pub fn reset_middlewares(self) -> MqttServer<St, C, Cn, P, Identity>
Remove all middlewares
sourcepub fn middleware<U>(self, mw: U) -> MqttServer<St, C, Cn, P, Stack<M, U>>
pub fn middleware<U>(self, mw: U) -> MqttServer<St, C, Cn, P, Stack<M, U>>
Registers middleware, in the form of a middleware component (type), that runs during inbound and/or outbound processing in the request lifecycle (request -> response), modifying request/response as necessary, across all requests managed by the Server.
Use middleware when you need to read or modify every request or response in some way.
sourcepub fn control<F, Srv>(self, service: F) -> MqttServer<St, C, Srv, P, M>where
F: IntoServiceFactory<Srv, Control<C::Error>, Session<St>>,
Srv: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
C::Error: From<Srv::Error> + From<Srv::InitError>,
pub fn control<F, Srv>(self, service: F) -> MqttServer<St, C, Srv, P, M>where
F: IntoServiceFactory<Srv, Control<C::Error>, Session<St>>,
Srv: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
C::Error: From<Srv::Error> + From<Srv::InitError>,
Service to handle control packets
All control packets are processed sequentially, max number of buffered control packets is 16.
sourcepub fn publish<F, Srv>(self, publish: F) -> MqttServer<St, C, Cn, Srv, M>where
F: IntoServiceFactory<Srv, Publish, Session<St>>,
C::Error: From<Srv::Error> + From<Srv::InitError>,
Srv: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
Srv::Error: Debug,
PublishAck: TryFrom<Srv::Error, Error = C::Error>,
pub fn publish<F, Srv>(self, publish: F) -> MqttServer<St, C, Cn, Srv, M>where
F: IntoServiceFactory<Srv, Publish, Session<St>>,
C::Error: From<Srv::Error> + From<Srv::InitError>,
Srv: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
Srv::Error: Debug,
PublishAck: TryFrom<Srv::Error, Error = C::Error>,
Set service to handle publish packets and create mqtt server factory
source§impl<St, C, Cn, P, M> MqttServer<St, C, Cn, P, M>where
St: 'static,
C: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static,
C::Error: From<Cn::Error> + From<Cn::InitError> + From<P::Error> + From<P::InitError> + Debug,
Cn: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
P: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
P::Error: Debug,
PublishAck: TryFrom<P::Error, Error = C::Error>,
impl<St, C, Cn, P, M> MqttServer<St, C, Cn, P, M>where
St: 'static,
C: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static,
C::Error: From<Cn::Error> + From<Cn::InitError> + From<P::Error> + From<P::InitError> + Debug,
Cn: ServiceFactory<Control<C::Error>, Session<St>, Response = ControlAck> + 'static,
P: ServiceFactory<Publish, Session<St>, Response = PublishAck> + 'static,
P::Error: Debug,
PublishAck: TryFrom<P::Error, Error = C::Error>,
sourcepub fn finish(
self,
) -> MqttServer<Session<St>, impl ServiceFactory<IoBoxed, Response = (IoBoxed, Rc<MqttShared>, Session<St>, Seconds), Error = MqttError<C::Error>, InitError = C::InitError>, impl ServiceFactory<DispatchItem<Rc<MqttShared>>, Session<St>, Response = Option<Packet>, Error = MqttError<C::Error>, InitError = MqttError<C::Error>>, M, Rc<MqttShared>>
pub fn finish( self, ) -> MqttServer<Session<St>, impl ServiceFactory<IoBoxed, Response = (IoBoxed, Rc<MqttShared>, Session<St>, Seconds), Error = MqttError<C::Error>, InitError = C::InitError>, impl ServiceFactory<DispatchItem<Rc<MqttShared>>, Session<St>, Response = Option<Packet>, Error = MqttError<C::Error>, InitError = MqttError<C::Error>>, M, Rc<MqttShared>>
Finish server configuration and create mqtt server factory