I want to use Dapr to subscribe to changes in an Azure App Configuration store as documented on this page: https://docs.dapr.io/reference/components-reference/supported-configuration-stores/azure-appconfig-configuration-store/
When I run my application I succesfully read the configuration from the Azure App Configuration store, however I do not receive any changes when I update the sentinelKey.
I have a .NET application that subscribes using the Dapr SDK with the following code:
/// <summary>
/// Subscribes to configuration changes using the DaprClient
/// and logs each change to the console in real time.
/// </summary>
/// <param name="stoppingToken"></param>
/// <returns></returns>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Console.WriteLine("Subscribing to configuration changes on the following keys:");
foreach (var key in CONFIGURATION_KEYS)
{
Console.WriteLine(key);
}
// Initialize the gRPC Stream that will provide configuration updates.
Dapr.Client.SubscribeConfigurationResponse subscribe = await _daprClient.SubscribeConfiguration(
DAPR_CONFIGURATION_STORE,
CONFIGURATION_KEYS,
new Dictionary<string, string>
{
{ "sentinelKey", "TestApp:Settings:Sentinel"}
}, stoppingToken);
// The response contains a data source which is an IAsyncEnumerable, so it can be iterated through via an awaited foreach.
await foreach (var configItems in subscribe.Source.WithCancellation(stoppingToken))
{
// First invocation when app subscribes to config changes only returns subscription id
if (configItems.Keys.Count == 0)
{
Console.WriteLine("Subscribed to config changes with subscription id: " + subscribe.Id);
continue;
}
var cfg = System.Text.Json.JsonSerializer.Serialize(configItems);
Console.WriteLine("Configuration update: " + cfg);
}
}
My Dapr configuration store component looks as follows:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: configstoreazureappconfig
spec:
type: configuration.azure.appconfig
version: v1
metadata:
- name: connectionString
value: <CONNECTION-STRING-HERE>
When I use this code with Redis as a config store it works as expected, configuration updates get sent to my application and are logged to the console. I do not receive any updates with Azure App Configuration even when I update the sentinelKey value in Azure.
When I run the application I get the following output:
| Subscribing to configuration changes on the following keys:
| orderId1
| orderId2
| TestApp:Settings:Sentinel
| info: Microsoft.Hosting.Lifetime[14]
| Now listening on: http://[::]:80
| info: Microsoft.Hosting.Lifetime[0]
| Application started. Press Ctrl+C to shut down.
| info: Microsoft.Hosting.Lifetime[0]
pocnativevoicesessions-poc.nativevoice.sessions-1 | Hosting environment: Development
| info: Microsoft.Hosting.Lifetime[0]
| Content root path: /app
| Subscribed to config changes with subscription id: 22b7dce1-7a89-4de1-bc57-87145937cc1f
| Configuration update: {"TestApp:Settings:Sentinel":{"Value":"8","Version":"","Metadata":{}},"orderId1":{"Value":"102","Version":"","Metadata":{}},"orderId2":{"Value":"10","Version":"","Metadata":{}}}
so I do get the configuration once when the application starts, I just don't get any updates. The Dapr sidecar also logs no erros.
I found this discussion on the implementation of subscribing to Azure App Configuration changes using Dapr: https://github.com/dapr/components-contrib/issues/2060
Does anyone know how to subscribe to Azure App Configuration changes using a Dapr configuration store component? Thanks in advance!
From the source code, it looks like you can subscribe for changes, but you must provide a sentinel key as part of the metadata.
Please also note that the defaultSubscribePollInterval is 24 hours. You may want to change it to something shorter, at least during your testing.