I have a problem related to updating values in Azure Configuration Manager. What is not clear to me is whether the update occurs only when the specified cache period elapses or if it should also occur when the value of the sentinel key is changed.
This is the code in my Program.cs.
var builder = WebApplication.CreateBuilder(args);
ConfigureServices();
var app = builder.Build();
Configure(app, app.Environment);
app.Run();
void ConfigureServices()
{
// Servizio per connettersi a AzureApp Configuration
builder.Services.AddAzureAppConfiguration();
builder.Configuration.AddAzureAppConfiguration(options =>
{
var connectionString = builder.Configuration.GetConnectionString("AppConfiguration");
options.Connect(connectionString)
.ConfigureRefresh(r => r.Register(key: "Settings:Refresh", refreshAll: true)
.SetCacheExpiration(TimeSpan.FromMinutes(10)));
});
...
}
void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseAzureAppConfiguration();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyApp v1"));
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
{
app.UseHttpsRedirection();
app.UseExceptionHandler("/Error");
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
From what I understand, if the value of the Settings:Refresh item is updated, the entire configuration should be updated.
I have created this simple Controller method to read the configuration:
[HttpGet()]
public IActionResult Test()
{
var settings = configuration.GetSection("Settings").GetChildren().ToList();
return Ok(settings);
}
However, even though I change the value of the sentinel key, the configuration is only updated when the cache expires.
What am I doing wrong?
The code that you are providing uses the poll model, that means that the sentinel will only be updated when cache expires.
If you want to make it refresh when the sentinel value changes, then you are going to need a push model. Basically what you do is create a service bus and connect it with app configuration, then you should make your application to listen on topic events.
Everything is described here.