pub struct Executor<TReq, TResp, C>where
TReq: PayloadSerialize + Send + 'static,
TResp: PayloadSerialize + Send + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,{ /* private fields */ }
Expand description
Command Executor struct
§Example
let executor_options = rpc_command::executor::OptionsBuilder::default()
.command_name("test_command")
.request_topic_pattern("test/request")
.build().unwrap();
let mut executor: rpc_command::Executor<Vec<u8>, Vec<u8>, _> = rpc_command::Executor::new(application_context, mqtt_session.create_managed_client(), executor_options).unwrap();
// let request = executor.recv().await.unwrap();
// let response = rpc_command::executor::ResponseBuilder::default()
// .payload(Vec::new()).unwrap()
// .build().unwrap();
// let request.complete(response).await.unwrap();
Implementations§
Source§impl<TReq, TResp, C> Executor<TReq, TResp, C>where
TReq: PayloadSerialize + Send + 'static,
TResp: PayloadSerialize + Send + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,
Implementation of Command Executor.
impl<TReq, TResp, C> Executor<TReq, TResp, C>where
TReq: PayloadSerialize + Send + 'static,
TResp: PayloadSerialize + Send + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,
Implementation of Command Executor.
Sourcepub fn new(
application_context: ApplicationContext,
client: C,
executor_options: Options,
) -> Result<Self, AIOProtocolError>
pub fn new( application_context: ApplicationContext, client: C, executor_options: Options, ) -> Result<Self, AIOProtocolError>
Create a new Executor
.
§Arguments
application_context
-ApplicationContext
that the command executor is part of.client
- The MQTT client to use for communication.executor_options
- Configuration options.
Returns Ok(Executor
) on success, otherwise returns AIOProtocolError
.
§Errors
AIOProtocolError
of kind ConfigurationInvalid
if:
command_name
is empty, whitespace or invalidrequest_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 Executor
. Unsubscribes from the request topic.
Note: If this method is called, the Executor
will no longer receive commands
from the MQTT client, any command requests that have not been processed can still be received
by the executor. 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<Request<TReq, TResp>, AIOProtocolError>>
pub async fn recv( &mut self, ) -> Option<Result<Request<TReq, TResp>, AIOProtocolError>>
Receive a command request or None
if there will be no more requests.
If there are messages:
- Returns Ok(
Request
) on success - Returns
AIOProtocolError
on error.
Will also subscribe to the request topic if not already subscribed.
§Errors
AIOProtocolError
of kind UnknownError
if an error occurs while receiving the message.
AIOProtocolError
of kind ClientError
if the subscribe fails or if the suback reason code doesn’t indicate success.
AIOProtocolError
of kind InternalLogicError
if the command expiration time cannot be calculated.