Skip to content

Azure Cosmos DB for NoSQL grain persistence

The Azure Cosmos DB grain persistence provider supports the API for NoSQL.

Install the Microsoft.Orleans.Persistence.Cosmos and Microsoft.Orleans.Clustering.Cosmos NuGet packages. The Azure Cosmos DB provider stores state in a container item.

To configure the clustering provider, use the HostingExtensions.UseCosmosClustering extension method. In this method, you can customize the name and throughput of the database or container, enable resource creation, or configure the client’s credentials.

siloBuilder.UseCosmosClustering(
configureOptions: static options =>
{
options.IsResourceCreationEnabled = true;
options.DatabaseName = "OrleansAlternativeDatabase";
options.ContainerName = "OrleansClusterAlternativeContainer";
options.ContainerThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000);
options.ConfigureCosmosClient("<azure-cosmos-db-nosql-connection-string>");
});

Configure the Azure Cosmos DB grain persistence provider using the HostingExtensions.AddCosmosGrainStorage extension method.

siloBuilder.AddCosmosGrainStorage(
name: "profileStore",
configureOptions: static options =>
{
options.IsResourceCreationEnabled = true;
options.DatabaseName = "OrleansAlternativeDatabase";
options.ContainerName = "OrleansStorageAlternativeContainer";
options.ContainerThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000);
options.ConfigureCosmosClient("<azure-cosmos-db-nosql-connection-string>");
});