Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

.net core - Force update Configuration using Azure App Configuration

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?

question from:https://stackoverflow.com/questions/65599039/force-update-configuration-using-azure-app-configuration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...