Orleans is a framework that provides a straight-forward approach to building distributed high-scale computing applications, without the need to learn and apply complex concurrency or other scaling patterns.
Azure CosmosDB is Microsoft's globally distributed, multi-model database. It is a database for extremely low latency and massively scalable applications anywhere in the world, with native support for NoSQL.
Orleans.CosmosDB is a package that use Azure CosmosDB as a backend for Orleans providers like Cluster Membership, Grain State storage, Streaming and Reminders.
Installation is performed via NuGet
From Package Manager:
PS> Install-Package Orleans.Clustering.CosmosDB -prerelease
PS> Install-Package Orleans.Persistence.CosmosDB -prerelease
PS> Install-Package Orleans.Reminders.CosmosDB -prerelease
.Net CLI:
# dotnet add package Orleans.Clustering.CosmosDB -prerelease
# dotnet add package Orleans.Persistence.CosmosDB -prerelease
# dotnet add package Orleans.Reminders.CosmosDB -prerelease
Paket:
# paket add Orleans.Clustering.CosmosDB -prerelease
# paket add Orleans.Persistence.CosmosDB -prerelease
# paket add Orleans.Reminders.CosmosDB -prerelease
It is not mandatory to use all the providers at once. Just pick the one you are interested in from the samples and you should be good as they don't depend on each other.
We need to configure the Orleans Silo with the below:
- Use
.UseCosmosDBMembership()
onISiloHostBuilder
to enable cluster membership. - Use
.AddAzureCosmosDBPersistence()
onClusterConfiguration
to register the grain state persistence provider. - Use
.UseAzureCosmosDBPersistence()
onISiloHostBuilder
to configure the grain state persistence provider. - Use
.AddAzureCosmosDBReminders()
onClusterConfiguration
to register the reminders provider. - Use
.UseAzureCosmosDBReminders()
onISiloHostBuilder
to configure the reminders provider.
Example
var siloConfig = new ClusterConfiguration();
siloConfig.AddAzureCosmosDBPersistence("myProvider"); //Register the persistence provider.
siloConfig.AddAzureCosmosDBReminders(); // Register the reminders provider.
var silo = new SiloHostBuilder()
.UseConfiguration(siloConfig)
.UseCosmosDBMembership() // Use CosmosDB as the cluster membership table.
.UseAzureCosmosDBPersistence() // Configure CosmosDB persistence provider.
.UseAzureCosmosDBReminders() // Configure CosmosDB reminders provider.
.Build();
await silo.StartAsync();
Now your client application needs to connect to the Orleans Cluster by using configuring the Gateway List Provider:
- Use
.UseCosmosDBGatewayListProvider()
onIClientBuilder
.
Example
var clientConfig = new ClientConfiguration();
var client = new ClientBuilder()
.UseConfiguration(clientConfig)
.UseCosmosDBGatewayListProvider() // Use CosmosDB as the Gateway list provider.
.Build();
await client.Connect();
Great! Now you have Orleans configured to use Azure CosmosDB as the back storage for its providers!
PRs and feedback are very welcome!