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.

Source

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:

Source

pub async fn invoke( &self, request: Request<TReq>, ) -> Result<Response<TResp>, AIOProtocolError>

Invokes a command.

Returns Ok(Response) on success, otherwise returns AIOProtocolError.

§Arguments
§Errors

AIOProtocolError of kind ConfigurationInvalid if

AIOProtocolError of kind PayloadInvalid if

AIOProtocolError of kind Timeout if

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

AIOProtocolError of kind HeaderMissing if

AIOProtocolError of kind UnknownError if

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

AIOProtocolError of kind StateInvalid if

Source

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.

Trait Implementations§

Source§

impl<TReq, TResp, C> Drop for Invoker<TReq, TResp, C>
where TReq: PayloadSerialize + 'static, TResp: PayloadSerialize + 'static, C: ManagedClient + Clone + Send + Sync + 'static, C::PubReceiver: Send + Sync + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<TReq, TResp, C> Freeze for Invoker<TReq, TResp, C>
where C: Freeze,

§

impl<TReq, TResp, C> !RefUnwindSafe for Invoker<TReq, TResp, C>

§

impl<TReq, TResp, C> Send for Invoker<TReq, TResp, C>
where TReq: Send, TResp: Send,

§

impl<TReq, TResp, C> Sync for Invoker<TReq, TResp, C>
where TReq: Sync, TResp: Sync,

§

impl<TReq, TResp, C> Unpin for Invoker<TReq, TResp, C>
where C: Unpin, TReq: Unpin, TResp: Unpin,

§

impl<TReq, TResp, C> !UnwindSafe for Invoker<TReq, TResp, C>

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V