Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Making BERT RPC calls in F#

theburningmonk edited this page Aug 22, 2012 · 1 revision

The full example is available in the F# example project here.

For more information regarding how BERT-RPC works, please refer to the BERT-RPC spec.

Getting Started

Before you can make BERT-RPC calls against a BERT-RPC server, you first need to create an instance of Filbert.Rpc.BertRpcClient using the static Start method:

let client = Filbert.Rpc.BertRpcClient.Start(serviceUrl, portNumber)

RPC Client - Call (synchronous request)

Once you have a client, use BertRpcClient.Call to make a synchronous call against a BERT-RPC server, this will return an instance of Async<Bert> which you can then use either in an async workflow or use Async.RunSynchronously to get the result right away.

Suppose there is a nat Erlang module running on the BERT-RPC server, which looks like this:

-module(nat).
-export([add/2, die/1]).

add(A, B) -> A + B.

die(X) -> X = 10.

To call nat.add(1, 100) and wait for the response synchronously, this is all you need to do:

// synchronous example
let result = client.Call("nat", "add", Integer 1, Integer 100) |> Async.RunSynchronously

Alternatively, you can wait for the response asynchronously:

// asynchronous example
async {
    let! result = client.Call("nat", "add", Integer 1, Integer 100)
    ... // do something with the result, printf, etc.
}
|> Async.Start

RPC Client - Cast (fire-and-forget request)

To make a cast call against a BERT-RPC server and wait for the acknowledgement synchronously:

// synchronous example
client.Cast("nat", "die", Integer 666) |>  Async.RunSynchronously

Again, it's easy to wait for the acknowledgement asynchronously instead:

// asynchronous example
async {
    do! client.Cast("nat", "die", Integer 666)
    ... // do something else
}
|> Async.Start