pub struct Receiver<T, C>where
T: PayloadSerialize + Send + Sync + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,{ /* private fields */ }
Expand description
Telemetry Receiver struct
§Example
let receiver_options = telemetry::receiver::OptionsBuilder::default()
.topic_pattern("test/telemetry")
.build().unwrap();
let mut receiver: telemetry::Receiver<Vec<u8>, _> = telemetry::Receiver::new(application_context, mqtt_session.create_managed_client(), receiver_options).unwrap();
// let telemetry_message = receiver.recv().await.unwrap();
Implementations§
Source§impl<T, C> Receiver<T, C>
Implementation of a Telemetry Sender
impl<T, C> Receiver<T, C>
Implementation of a Telemetry Sender
Sourcepub fn new(
application_context: ApplicationContext,
client: C,
receiver_options: Options,
) -> Result<Self, AIOProtocolError>
pub fn new( application_context: ApplicationContext, client: C, receiver_options: Options, ) -> Result<Self, AIOProtocolError>
Creates a new Receiver
.
§Arguments
application_context
-ApplicationContext
that the telemetry receiver is part of.client
- [ManagedClient
] to use for telemetry communication.receiver_options
-Options
to configure the telemetry receiver.
Returns Ok(Receiver
) on success, otherwise returnsAIOProtocolError
.
§Errors
AIOProtocolError
of kind ConfigurationInvalid
topic_pattern
,topic_namespace
, are Some and invalid or contain a token with no valid replacementtopic_token_map
is not empty and contains invalid key(s) and/or token(s)
Sourcepub async fn shutdown(&mut self) -> Result<(), AIOProtocolError>
pub async fn shutdown(&mut self) -> Result<(), AIOProtocolError>
Shutdown the Receiver
. Unsubscribes from the telemetry topic if subscribed.
Note: If this method is called, the Receiver
will no longer receive telemetry messages
from the MQTT client, any messages that have not been processed can still be received by the
receiver. If the method returns an error, it may be called again to attempt the unsubscribe again.
Returns Ok(()) on success, otherwise returns AIOProtocolError
.
§Errors
AIOProtocolError
of kind ClientError
if the unsubscribe fails or if the unsuback reason code doesn’t indicate success.
Sourcepub async fn recv(
&mut self,
) -> Option<Result<(Message<T>, Option<AckToken>), AIOProtocolError>>
pub async fn recv( &mut self, ) -> Option<Result<(Message<T>, Option<AckToken>), AIOProtocolError>>
Receives a telemetry message or None
if there will be no more messages.
If there are messages:
- Returns Ok(
Message
,Option<AckToken>
) on success- If the message is received with Quality of Service 1 an [
AckToken
] is returned.
- If the message is received with Quality of Service 1 an [
- Returns
AIOProtocolError
on error.
A received message can be acknowledged via the [AckToken
] by calling [AckToken::ack
] or dropping the [AckToken
].
Will also subscribe to the telemetry topic if not already subscribed.
§Errors
AIOProtocolError
of kind ClientError
if the subscribe fails or if the suback reason code doesn’t indicate success.