This Library provides an API to register an Orleans Client in an application.
The below code needs to be added to the Startup.cs
. This will register an Orleans Client.
public void ConfigureServices(IServiceCollection services)
{
services.AddDefaultClusterClient((x, sp) =>
{
x.ConfigureCluster(_configuration);
x.AddAssemblies(typeof(IGrain));
});
}
The below table outlines the valid Configurations used to override the ClusterOptions under the Config section Orleans:Cluster
.
Configuration Name | Type | Optional | Default Value |
---|---|---|---|
ClusterId | String | Yes | dev |
ServiceId | String | Yes | dev |
The ClusterClientFactory can be used to register multiple named Orleans Cluster Clients.
The below code creates, sets up and registers an ClusterClientFactory. Cluster Clients can be added to the factory either via a created instance or an anonymous Func.
public void ConfigureServices(IServiceCollection services)
{
var clusterB = services.CreateClusterClient((builder) =>
{
builder.ConfigureCluster(ctx.Configuration.GetSection("Orleans:ClusterB"));
});
services.AddClusterClientFactory()
.AddClusterClient("ClusterA", () =>
{
return services.CreateClusterClient((builder) =>
{
builder.ConfigureCluster(ctx.Configuration.GetSection("Orleans:ClusterA"));
});
})
.AddClusterClient("ClusterB", clusterB);
}
The below code is an example of how the ClusterClientFactory can be used. A sample usage can also be found in the sample controller EchoController.
private readonly IClusterClientFactory _clusterClientFactory;
public async Task<string> PingAsync(string clusterName, string graindId)
{
var clusterClient = _clusterClientFactory.Get(clusterName);
var grain = clusterClient.GetGrain<IEchoGrain>(grainId);
return await grain.Ping();
}
If you use the below extension method to configure the Cluster Client, the Builder would expect the Cluster Configuration section to be Orleans:Cluster:{ClusterName}
.
services.CreateClusterClient((builder) =>
{
builder.ConfigureCluster("ClusterA", _configuration);
});
Sample Configuration:
{
"Orleans": {
"Cluster": {
"ClusterA": {
"ClusterId": "dev1",
"ServiceId": "sample1"
},
"ClusterB": {
"ClusterId": "dev2",
"ServiceId": "sample2"
}
}
}
}