You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a project where I have an Azure Cosmos DB that I want to use as a Dapr State store, however I'm attempting to leverage Aspire to stand up the Cosmos DB resource in Azure for individual developers.
The difficulty I'm running into is with configuring the Dapr state store to provide the URL to my (potentially newly deployed) Cosmos DB. The WithMetadata extension method appears to provide functionality similar to this, however as far as I can tell the metadata is getting written at build time and isn't getting replaced at run time with an actual connection string.
The code looks a bit like this:
usingCommunityToolkit.Aspire.Hosting.Dapr;usingMicrosoft.Extensions.Hosting;varbuilder=DistributedApplication.CreateBuilder(args);varcosmos=builder.AddAzureCosmosDB("cosmos-db");vardb=cosmos.AddCosmosDatabase("datastore-db");db.AddContainer("widgets","/partitionKey");// Must set partition key to "/partitionKey" for dapr - https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-azure-cosmosdb/#setup-azure-cosmosdbvardaprStateStore=builder.AddDaprStateStore("my-statestore",newDaprComponentOptions{LocalPath="../MyDemoProject/.dapr/components/cosmosdb-statestore.yaml"});// This doesn't seem to workdaprStateStore.WithMetadata("url",cosmos.Resource.ConnectionStringExpression.ValueExpression);builder.AddProject<Projects.MyDemoProject>("mydemoproject").WithDaprSidecar().WithReference(daprStateStore).WithReference(cosmos).WaitFor(cosmos);builder.Build().Run();
And for reference here is what the cosmosdb-statestore.yaml file looks like:
apiVersion: dapr.io/v1alpha1kind: Componentmetadata:
name: my-statestorespec:
type: state.azure.cosmosdbversion: v1initTimeout: 5mmetadata:
# URL metadata to be filled in by .net aspire or during deployment.# - name: url# value: https://<cosmosdb-name>.documents.azure.com:443/
- name: databasevalue: "datastore-db"
- name: collectionvalue: "widgets"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on a project where I have an Azure Cosmos DB that I want to use as a Dapr State store, however I'm attempting to leverage Aspire to stand up the Cosmos DB resource in Azure for individual developers.
The difficulty I'm running into is with configuring the Dapr state store to provide the URL to my (potentially newly deployed) Cosmos DB. The
WithMetadata
extension method appears to provide functionality similar to this, however as far as I can tell the metadata is getting written at build time and isn't getting replaced at run time with an actual connection string.The code looks a bit like this:
And for reference here is what the cosmosdb-statestore.yaml file looks like:
Quick Diagram:
MyDemoProject -----> Dapr Sidecar ----> cosmosdb statestore component ---> CosmosDB running in Azure
Beta Was this translation helpful? Give feedback.
All reactions