Async rpc: how to make a persistant rpc connection

Hi all I’m trying to get my head around how the Async ecosystem connects together.

I’m aiming to have a persistant rpc connection to some set of services. I can see that there is a way to create persistant connections: Persistant_connection_kernel, however it isn’t obvious to me how use that, and additionally how to inject the result into the rpc connection system: Rpc.Connection.create.

I can see that there is an create method which takes a Transport.t though I can’t quite see how to pipe everything through (additionally it looks like there are two create methods which should alias each other?)

Async_rpc_kernel.Persistent_connection.Rpc is a pre-packaged persistent connection module which gives you Rpc.Connection.ts. It uses Host_and_port.t as the address type and Rpc.Connection.t as the connection type.

For example, you could do something like:

let _ =
  let persistent_connection =
      ~server_name:"RPC server"
      ~connect:(fun host_and_port ->
          (Tcp.Where_to_connect.of_host_and_port host_and_port))
      (fun () -> server_address)
  let%bind conn = Async_rpc_kernel.Persistent_connection.Rpc.connected persistent_connection in
  (* do something with the RPC connection *)
1 Like

Brilliant thanks!! That is exactly what I was looking for! I think I was looking at an old version of the API…

1 Like