Skip to content

Client Configuration

Complete clientConfig CE reference for configuring an Orleans client.

Guide to the clientConfig { } computation expression.

  • How to configure an Orleans client to connect to a silo
  • Clustering modes: localhost, static gateways
  • TLS for secure client connections
  • Custom DI services on the client

The clientConfig { } CE builds a ClientConfig record. Apply it to a host or build it directly:

open Orleans.FSharp.Runtime
let config = clientConfig {
useLocalhostClustering
}
// Option 1: Apply to a HostApplicationBuilder
let builder = HostApplicationBuilder()
ClientConfig.applyToHost config builder
// Option 2: Build directly (creates a host and returns the client)
let host, client = ClientConfig.build config
host.StartAsync().GetAwaiter().GetResult()

Connect to a single local silo for development:

clientConfig { useLocalhostClustering }

Connect to known silo endpoints:

clientConfig {
useStaticClustering [ "10.0.0.1:30000"; "10.0.0.2:30000" ]
}

Each endpoint must be in "host:port" format.


clientConfig {
useLocalhostClustering
clusterId "my-cluster"
serviceId "my-service"
}

The clusterId and serviceId must match the silo configuration.


How often the client refreshes its list of available gateways:

clientConfig {
useLocalhostClustering
gatewayListRefreshPeriod (TimeSpan.FromSeconds 30.)
}

Set the preferred gateway index for client connections:

clientConfig {
useLocalhostClustering
preferredGatewayIndex 0
}

clientConfig {
useLocalhostClustering
addMemoryStreams "StreamProvider"
}

clientConfig {
useLocalhostClustering
useTls "CN=my-client-cert"
}
let cert = new X509Certificate2("path/to/cert.pfx", "password")
clientConfig {
useLocalhostClustering
useTlsWithCertificate cert
}
clientConfig {
useLocalhostClustering
useMutualTls "CN=my-client-cert"
}

Register services on the client’s DI container:

clientConfig {
useLocalhostClustering
configureServices (fun services ->
services.AddSingleton<IMyService, MyService>() |> ignore)
}

open System
open Orleans
open Orleans.FSharp
open Orleans.FSharp.Runtime
open Microsoft.Extensions.DependencyInjection
let config = clientConfig {
useStaticClustering [ "10.0.0.1:30000"; "10.0.0.2:30000" ]
clusterId "production"
serviceId "my-app"
useMutualTls "CN=orleans-client"
gatewayListRefreshPeriod (TimeSpan.FromSeconds 30.)
addMemoryStreams "Events"
}
let host, client = ClientConfig.build config
host.StartAsync().GetAwaiter().GetResult()
// Get a grain reference and make calls
let counterRef = GrainRef.ofString<ICounterGrain> (client :> IGrainFactory) "my-counter"
let! result = GrainRef.invoke counterRef (fun g -> g.Increment())