package amqp-client-async

  1. Overview
  2. Docs

Rpc Client pattern

type t
val init : id:string -> Connection.t -> t Thread.Deferred.t

Initialize a client with the id for tracing

val call : t -> ?correlation_id:string -> ttl:int -> ?grace_time_ms:int -> routing_key:string -> headers:Amqp_client_lib.Types.header list -> _ Exchange.t -> (Spec.Basic.Content.t * string) -> Message.message option Thread.Deferred.t

Make an rpc call to the exchange using the routing key and headers.

  • parameter ttl

    is the message timeout in milliseconds. If the message is on the rpc endpoints queue for more than ttl milliseconds the message will be dead lettered and returned which will cause this function to timeout and return None.

  • parameter grace_time_ms

    is the time added to the ttl before the function times out and returns None This is to give the rpc serve a chance to process the message, in case the rpc server consumed the message from the queue close to ttl. Default 100ms.

    To call directly to a named queue, use call t Exchange.default ~ttl:500 ~routing_key:"name_of_the_queue" ~headers:[]

    correlation_id allows you to specify a correlation id. The id will be suffixed with an id to allow the caller to reuse correlation ids. This can be used for tracing by reusing correlation ids of incomming requests resulting in new calls. If no correlation is given the id of the client is used.

    The function allows the call to specify both a routing key and headers regardless of the type of exchange used, as exchanges may be chained in a way where both headers and routing keys are used.

    This function will timeout and return None, either if the request message is dead-lettered or if ttl + grace_time_ms has passed.

val close : t -> unit Thread.Deferred.t

Release resources