pub struct Invoker<TReq, TResp, C>where
TReq: PayloadSerialize + 'static,
TResp: PayloadSerialize + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,{ /* private fields */ }Expand description
Command Invoker struct
§Example
let invoker_options = rpc_command::invoker::OptionsBuilder::default()
.request_topic_pattern("test/request")
.response_topic_pattern("test/response".to_string())
.command_name("test_command")
.topic_namespace("test_namespace".to_string())
.topic_token_map(HashMap::from([("invokerClientId".to_string(), "test_client".to_string())]))
.response_topic_prefix("custom/{invokerClientId}".to_string())
.build().unwrap();
let invoker: rpc_command::Invoker<Vec<u8>, Vec<u8>, _> = rpc_command::Invoker::new(application_context, mqtt_session.create_managed_client(), invoker_options).unwrap();
let request = rpc_command::invoker::RequestBuilder::default()
.payload(Vec::new()).unwrap()
.timeout(Duration::from_secs(2))
.topic_tokens(HashMap::from([("executorId".to_string(), "test_executor".to_string())]))
.build().unwrap();
let result = invoker.invoke(request);
//let response: Response<Vec<u8>> = result.await.unwrap();Implementations§
Source§impl<TReq, TResp, C> Invoker<TReq, TResp, C>where
TReq: PayloadSerialize + 'static,
TResp: PayloadSerialize + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,
Implementation of Command Invoker.
impl<TReq, TResp, C> Invoker<TReq, TResp, C>where
TReq: PayloadSerialize + 'static,
TResp: PayloadSerialize + 'static,
C: ManagedClient + Clone + Send + Sync + 'static,
C::PubReceiver: Send + Sync + 'static,
Implementation of Command Invoker.
Sourcepub fn new(
application_context: ApplicationContext,
client: C,
invoker_options: Options,
) -> Result<Self, AIOProtocolError>
pub fn new( application_context: ApplicationContext, client: C, invoker_options: Options, ) -> Result<Self, AIOProtocolError>
Creates a new Invoker.
§Arguments
application_context-ApplicationContextthat the command invoker is part of.client- The MQTT client to use for communication.invoker_options- Configuration options.
Returns Ok(Invoker) on success, otherwise returns AIOProtocolError.
§Errors
AIOProtocolError of kind ConfigurationInvalid if:
command_nameis empty, whitespace or invalidrequest_topic_patternis empty or whitespaceresponse_topic_patternis Some and empty or whitespaceresponse_topic_patternis None andresponse_topic_prefixorresponse_topic_suffixare Some and empty or whitespace
request_topic_pattern,response_topic_pattern,topic_namespace,response_topic_prefix,response_topic_suffix, are Some and invalid or contain a token with no valid replacementtopic_token_mapisn’t empty and contains invalid key(s)/token(s)
Sourcepub async fn invoke(
&self,
request: Request<TReq>,
) -> Result<Response<TResp>, AIOProtocolError>
pub async fn invoke( &self, request: Request<TReq>, ) -> Result<Response<TResp>, AIOProtocolError>
Invokes a command.
Returns Ok(Response) on success, otherwise returns AIOProtocolError.
§Arguments
request-Requestto invoke
§Errors
AIOProtocolError of kind ConfigurationInvalid if
- any
topic_tokensare invalid
AIOProtocolError of kind PayloadInvalid if
response_payloaddeserialization fails- The response has a
UserProperty::Statusof [StatusCode::NoContent] but the payload isn’t empty - The response has a
UserProperty::Statusof [StatusCode::BadRequest] and there is noUserProperty::InvalidPropertyNameorUserProperty::InvalidPropertyValuespecified
AIOProtocolError of kind Timeout if
- Command invoke timed out
- The response has a
UserProperty::Statusof [StatusCode::RequestTimeout]
AIOProtocolError of kind ClientError if
- The subscribe fails
- The suback reason code doesn’t indicate success.
- The publish fails
- The puback reason code doesn’t indicate success.
AIOProtocolError of kind Cancellation if the Invoker has been dropped
AIOProtocolError of kind HeaderInvalid if
- The response’s
content_typeisn’t supported - The response has a
UserProperty::Timestampthat is malformed - The response has a
UserProperty::Statusthat can’t be parsed as an integer - The response has a
UserProperty::Statusof [StatusCode::BadRequest] and aUserProperty::InvalidPropertyValueis specified - The response has a
UserProperty::Statusof [StatusCode::UnsupportedMediaType]
AIOProtocolError of kind HeaderMissing if
- The response has a
UserProperty::Statusof [StatusCode::BadRequest] andUserProperty::InvalidPropertyNameis specified, butUserProperty::InvalidPropertyValueisn’t specified - The response doesn’t specify a
UserProperty::Status
AIOProtocolError of kind UnknownError if
- The response has a
UserProperty::Statusthat isn’t one of [StatusCode] - The response has a
UserProperty::Statusof [StatusCode::InternalServerError], theUserProperty::IsApplicationErroris false, and aUserProperty::InvalidPropertyNameisn’t provided
AIOProtocolError of kind ExecutionException if the response has a UserProperty::Status of [StatusCode::InternalServerError] and the UserProperty::IsApplicationError is true
AIOProtocolError of kind InternalLogicError if
- the
ApplicationHybridLogicalClock’s counter would be incremented and overflow beyondu64::MAX - the response has a
UserProperty::Statusof [StatusCode::InternalServerError], theUserProperty::IsApplicationErroris false, and aUserProperty::InvalidPropertyNameis provided
AIOProtocolError of kind StateInvalid if
- the
ApplicationHybridLogicalClockor the received timestamp on the response is too far in the future - the response has a
UserProperty::Statusof [StatusCode::ServiceUnavailable]
Sourcepub async fn shutdown(&self) -> Result<(), AIOProtocolError>
pub async fn shutdown(&self) -> Result<(), AIOProtocolError>
Shutdown the Invoker. Unsubscribes from the response topic and closes the
MQTT receiver to stop receiving messages.
Note: If this method is called, the Invoker should not be used again.
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.