Azure Cosmos DB
To setup Azure CosmosDb state store create a component of type . See this guide on how to create and apply a state store configuration.
Warning
The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.
If you wish to use CosmosDb as an actor store, append the following to the yaml.
Spec metadata fields
Follow the instructions from the Azure documentation on how to create an Azure CosmosDB account. The database and collection must be created in CosmosDB before Dapr can use it.
In order to setup CosmosDB as a state store, you need the following properties:
- URL: the CosmosDB url. for example:
- Master Key: The key to authenticate to the CosmosDB account
- Collection: The name of the collection
Data format
To use the CosmosDB state store, your data must be sent to Dapr in JSON-serialized. Having it just JSON serializable will not work.
If you are using the Dapr SDKs (e.g. ) the SDK will serialize your data to json.
For examples see the curl operations in the Partition keys section.
The following operation will use nihilus
as the partition key value sent to CosmosDB:
For non-actor state operations, if you want to control the CosmosDB partition, you can specify it in metadata. Reusing the example above, here’s how to put it under the mypartition
partition
For actor state operations, the partition key is generated by Dapr using the , the actor type, and the actor id, such that data for the same actor always ends up under the same partition (you do not need to specify it). This is because actor state operations must use transactions, and in CosmosDB the items in a transaction must be on the same partition.
Related links
- Basic schema for a Dapr component
- Read for instructions on configuring state store components
- State management building block