Struct ntex_mqtt::v3::MqttServer

source ·
pub struct MqttServer<St, H, C, P> { /* private fields */ }
Expand description

Mqtt v3.1.1 server

St - connection state H - handshake service C - service for handling control messages P - service for handling publish

Every mqtt connection is handled in several steps. First step is handshake. Server calls handshake service with Handshake message, during this step service can authenticate connect packet, it must return instance of connection state St.

Handshake service could be expressed as simple function:

use ntex_mqtt::v3::{Handshake, HandshakeAck};

async fn handshake(hnd: Handshake) -> Result<HandshakeAkc<MyState>, MyError> {
    Ok(hnd.ack(MyState::new(), false))
}

During next stage, control and publish services get constructed, both factories receive Session<St> state object as an argument. Publish service handles Publish packet. On success, server server sends PublishAck packet to the client, in case of error connection get closed. Control service receives all other packets, like Subscribe, Unsubscribe etc. Also control service receives errors from publish service and connection disconnect.

Implementations§

source§

impl<St, H> MqttServer<St, H, DefaultControlService<St, H::Error>, DefaultPublishService<St, H::Error>>
where St: 'static, H: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static, H::Error: Debug,

source

pub fn new<F>(handshake: F) -> Self
where F: IntoServiceFactory<H, Handshake>,

Create server factory and provide handshake service

source§

impl<St, H, C, P> MqttServer<St, H, C, P>
where St: 'static, H: ServiceFactory<Handshake, Response = HandshakeAck<St>> + 'static, C: ServiceFactory<ControlMessage<H::Error>, Session<St>, Response = ControlResult> + 'static, P: ServiceFactory<Publish, Session<St>, Response = ()> + 'static, H::Error: From<C::Error> + From<C::InitError> + From<P::Error> + From<P::InitError> + Debug,

source

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.

source

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.

source

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 payload read rate is disabled.

source

pub fn max_qos(self, qos: QoS) -> Self

Set max allowed QoS.

If peer sends publish with higher qos then ProtocolError::MaxQoSViolated(..) By default max qos is set to ExactlyOnce.

source

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

source

pub fn inflight(self, val: u16) -> Self

Number of in-flight concurrent messages.

By default in-flight is set to 16 messages

source

pub fn inflight_size(self, val: usize) -> Self

Total size of in-flight messages.

By default total in-flight size is set to 64Kb

source

pub fn control<F, Srv>(self, service: F) -> MqttServer<St, H, Srv, P>
where F: IntoServiceFactory<Srv, ControlMessage<H::Error>, Session<St>>, Srv: ServiceFactory<ControlMessage<H::Error>, Session<St>, Response = ControlResult> + 'static, H::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.

source

pub fn publish<F, Srv>(self, publish: F) -> MqttServer<St, H, C, Srv>
where F: IntoServiceFactory<Srv, Publish, Session<St>>, Srv: ServiceFactory<Publish, Session<St>, Response = ()> + 'static, H::Error: From<Srv::Error> + From<Srv::InitError> + Debug,

Set service to handle publish packets and create mqtt server factory

source

pub fn finish( self ) -> MqttServer<Session<St>, impl ServiceFactory<IoBoxed, Response = (IoBoxed, Rc<MqttShared>, Session<St>, Seconds), Error = MqttError<H::Error>, InitError = H::InitError>, impl ServiceFactory<DispatchItem<Rc<MqttShared>>, Session<St>, Response = Option<Packet>, Error = MqttError<H::Error>, InitError = MqttError<H::Error>>, Rc<MqttShared>>

Finish server configuration and create mqtt server factory

Auto Trait Implementations§

§

impl<St, H, C, P> !RefUnwindSafe for MqttServer<St, H, C, P>

§

impl<St, H, C, P> !Send for MqttServer<St, H, C, P>

§

impl<St, H, C, P> !Sync for MqttServer<St, H, C, P>

§

impl<St, H, C, P> Unpin for MqttServer<St, H, C, P>
where C: Unpin, H: Unpin, P: Unpin, St: Unpin,

§

impl<St, H, C, P> !UnwindSafe for MqttServer<St, H, C, P>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more