0

I want to use dynamic and central configuration strategy for my microservices (MS) (multiple instances of same type having same configuration) and I'm using Azure App Configuration (AAC). I want to minimize calls to AAC so when one MS is starting I would like to read configuration from AAC and keep that until changes made i.e I dont want for every call to Configuration["Env:service:some-param"] generate calls to AAC. The notification part I have solved via eventgrid and servicebus-events so all MSs reaches notification that changes have been made but I really cant find any good solution to force to reload Configuration from AAC on demand. In Program.cs I hook up AAC via:

config.AddAzureAppConfiguration(options =>
                       options
                          .Connect(connection)
                          .ConfigureRefresh(refresh =>
                          {
                              refresh.Register(environment + ":" + service + ":<Some-param>",true)
                                     .SetCacheExpiration(TimeSpan.FromDays(1));
                              _environmentRefresher = options.GetRefresher();
                          })

why I set SetCacheExpiration(TimeSpan.FromDays(1)) is because I dont want to make unnecessary calls to AAC and I thought that if I fetch the refresher and triggers it when event occurs configuration would be reloaded but thats seems not to be the case due to SetCacheExpiration seems to override everything so my question is ... Is given scenario not solvable in .net core or can I achieve this in some way?

user3154653
  • 203
  • 1
  • 11

1 Answers1

3

Make sure to call IConfigurationRefresher.SetDirty if you want to force the cache expiration to occur using an event based refresh model. Otherwise you'll encounter the problem you mention where the cache hasn't been invalidated yet and the refresh call will be a no-op.

J. Campbell
  • 680
  • 4
  • 5
  • In my case, rather than broadcasting config changes to each MS, i am planning to notify to one MS which in turn will ask all other MS to refresh configuration via an api call. Is this possible? Seems like there is no method like Configuration.Refresh() that can be used for this purpose. Can this be done ? – user2058413 Feb 03 '23 at 07:33