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
-ApplicationContext
that 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_name
is empty, whitespace or invalidrequest_topic_pattern
is empty or whitespaceresponse_topic_pattern
is Some and empty or whitespaceresponse_topic_pattern
is None andresponse_topic_prefix
orresponse_topic_suffix
are 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_map
isn’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
-Request
to invoke
§Errors
AIOProtocolError
of kind ConfigurationInvalid
if
- any
topic_tokens
are invalid
AIOProtocolError
of kind PayloadInvalid
if
response_payload
deserialization fails- The response has a
UserProperty::Status
ofStatusCode::NoContent
but the payload isn’t empty - The response has a
UserProperty::Status
ofStatusCode::BadRequest
and there is noUserProperty::InvalidPropertyName
orUserProperty::InvalidPropertyValue
specified
AIOProtocolError
of kind Timeout
if
- Command invoke timed out
- The response has a
UserProperty::Status
ofStatusCode::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_type
isn’t supported - The response has a
UserProperty::Timestamp
that is malformed - The response has a
UserProperty::Status
that can’t be parsed as an integer - The response has a
UserProperty::Status
ofStatusCode::BadRequest
and aUserProperty::InvalidPropertyValue
is specified - The response has a
UserProperty::Status
ofStatusCode::UnsupportedMediaType
AIOProtocolError
of kind HeaderMissing
if
- The response has a
UserProperty::Status
ofStatusCode::BadRequest
andUserProperty::InvalidPropertyName
is specified, butUserProperty::InvalidPropertyValue
isn’t specified - The response doesn’t specify a
UserProperty::Status
AIOProtocolError
of kind UnknownError
if
- The response has a
UserProperty::Status
that isn’t one ofStatusCode
- The response has a
UserProperty::Status
ofStatusCode::InternalServerError
, theUserProperty::IsApplicationError
is false, and aUserProperty::InvalidPropertyName
isn’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::Status
ofStatusCode::InternalServerError
, theUserProperty::IsApplicationError
is false, and aUserProperty::InvalidPropertyName
is provided
AIOProtocolError
of kind StateInvalid
if
- the
ApplicationHybridLogicalClock
or the received timestamp on the response is too far in the future - the response has a
UserProperty::Status
ofStatusCode::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.