Skip to content

Commit 28d0043

Browse files
committed
update docs to use registerall in dotnet refresh examples
1 parent 1471148 commit 28d0043

6 files changed

+37
-35
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ In this tutorial, you learn how to:
2525

2626
Finish the quickstart: [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md).
2727

28-
## Add a sentinel key
29-
30-
A *sentinel key* is a key that you update after you complete the change of all other keys. Your app monitors the sentinel key. When a change is detected, your app refreshes all configuration values. This approach helps to ensure the consistency of configuration in your app and reduces the overall number of requests made to your App Configuration store, compared to monitoring all keys for changes.
31-
32-
1. In the Azure portal, open your App Configuration store and select **Configuration Explorer > Create > Key-value**.
33-
1. For **Key**, enter *TestApp:Settings:Sentinel*. For **Value**, enter 1. Leave **Label** and **Content type** blank.
34-
1. Select **Apply**.
35-
3628
## Reload data from App Configuration
3729

3830
1. Open *Program.cs*, and update the `AddAzureAppConfiguration` method you added during the quickstart. You can connect to App Configuration using either Microsoft Entra ID (recommended) or a connection string. The following code snippet demonstrates using Microsoft Entra ID.
@@ -44,17 +36,17 @@ A *sentinel key* is a key that you update after you complete the change of all o
4436
builder.Configuration.AddAzureAppConfiguration(options =>
4537
{
4638
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
47-
// Load all keys that start with `TestApp:` and have no label
39+
// Load all keys that start with `TestApp:` and have no label.
4840
.Select("TestApp:*", LabelFilter.Null)
49-
// Configure to reload configuration if the registered sentinel key is modified
41+
// Reload configuration if any selected key-values have changed.
5042
.ConfigureRefresh(refreshOptions =>
51-
refreshOptions.Register("TestApp:Settings:Sentinel", refreshAll: true));
43+
refreshOptions.RegisterAll());
5244
});
5345
```
5446

5547
The `Select` method is used to load all key-values whose key name starts with *TestApp:* and that have *no label*. You can call the `Select` method more than once to load configurations with different prefixes or labels. If you share one App Configuration store with multiple apps, this approach helps load configuration only relevant to your current app instead of loading everything from your store.
5648

57-
In the `ConfigureRefresh` method, you register keys you want to monitor for changes in your App Configuration store. The `refreshAll` parameter to the `Register` method indicates that all configurations you specified by the `Select` method will be reloaded if the registered key changes.
49+
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload the entire configuration whenever it detects a change in any of the selected key-values (those starting with *TestApp:* and having no label). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
5850

5951
> [!TIP]
6052
> You can add a call to the `refreshOptions.SetRefreshInterval` method to specify the minimum time between configuration refreshes. In this example, you use the default value of 30 seconds. Adjust to a higher value if you need to reduce the number of requests made to your App Configuration store.
@@ -108,7 +100,7 @@ You've set up your app to use the [options pattern in ASP.NET Core](/aspnet/core
108100

109101
## Request-driven configuration refresh
110102

111-
The configuration refresh is triggered by the incoming requests to your web app. No refresh will occur if your app is idle. When your app is active, the App Configuration middleware monitors the sentinel key, or any other keys you registered for refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the cache expiration time you set has passed.
103+
The configuration refresh is triggered by the incoming requests to your web app. No refresh will occur if your app is idle. When your app is active, the App Configuration middleware monitors any keys you registered for refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the cache expiration time you set has passed.
112104

113105
- If a request to App Configuration for change detection fails, your app will continue to use the cached configuration. New attempts to check for changes will be made periodically while there are new incoming requests to your app.
114106
- The configuration refresh happens asynchronously to the processing of your app's incoming requests. It will not block or slow down the incoming request that triggered the refresh. The request that triggered the refresh may not get the updated configuration values, but later requests will get new configuration values.
@@ -134,14 +126,13 @@ The configuration refresh is triggered by the incoming requests to your web app.
134126

135127
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created in the quickstart.
136128
137-
1. Select **Configuration explorer**, and update the values of the following keys. Remember to update the sentinel key at last.
129+
1. Select **Configuration explorer**, and update the values of the following keys.
138130

139131
| Key | Value |
140132
|---|---|
141133
| TestApp:Settings:BackgroundColor | green |
142134
| TestApp:Settings:FontColor | lightGray |
143135
| TestApp:Settings:Message | Data from Azure App Configuration - now with live updates! |
144-
| TestApp:Settings:Sentinel | 2 |
145136

146137
1. Refresh the browser a few times. When the cache expires after 30 seconds, the page shows with updated content.
147138

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-netfx.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Add the following key-values to the App Configuration store and leave **Label**
3838
| *TestApp:Settings:FontColor* | *Black* |
3939
| *TestApp:Settings:FontSize* | *40* |
4040
| *TestApp:Settings:Message* | *Data from Azure App Configuration* |
41-
| *TestApp:Settings:Sentinel* | *v1* |
4241

4342
## Create an ASP.NET Web Application
4443

@@ -78,10 +77,10 @@ Add the following key-values to the App Configuration store and leave **Label**
7877
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
7978
// Load all keys that start with `TestApp:` and have no label.
8079
.Select("TestApp:*")
81-
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
80+
// Reload configuration if any selected key-values have changed.
8281
.ConfigureRefresh(refresh =>
8382
{
84-
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
83+
refresh.RegisterAll()
8584
.SetRefreshInterval(new TimeSpan(0, 5, 0));
8685
});
8786
_configurationRefresher = options.GetRefresher();
@@ -92,7 +91,7 @@ Add the following key-values to the App Configuration store and leave **Label**
9291
```
9392
The `Application_Start` method is called upon the first request to your web application. It is called only once during the application's life cycle. As such it is a good place to initialize your `IConfiguration` object and load data from App Configuration.
9493

95-
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `refreshAll` parameter to the `Register` method indicates that all configuration values should be refreshed if the registered key changes. In this example, the key *TestApp:Settings:Sentinel* is a *sentinel key* that you update after you complete the change of all other keys. When a change is detected, your application refreshes all configuration values. This approach helps to ensure the consistency of configuration in your application compared to monitoring all keys for changes.
94+
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload the entire configuration whenever it detects a change in any of the selected key-values (those starting with *TestApp:* and having no label). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
9695

9796
The `SetRefreshInterval` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 5 minutes instead. It reduces the potential number of requests made to your App Configuration store.
9897

@@ -178,14 +177,13 @@ Add the following key-values to the App Configuration store and leave **Label**
178177

179178
![App launch local](./media/dotnet-fx-web-app-launch.png)
180179

181-
1. In the Azure portal, navigate to the **Configuration explorer** of your App Configuration store, and update the value of the following keys. Remember to update the sentinel key *TestApp:Settings:Sentinel* at last.
180+
1. In the Azure portal, navigate to the **Configuration explorer** of your App Configuration store, and update the value of the following keys.
182181

183182
| Key | Value |
184183
|------------------------------------|--------------------------------------------------------------|
185184
| *TestApp:Settings:BackgroundColor* | *Green* |
186185
| *TestApp:Settings:FontColor* | *LightGray* |
187186
| *TestApp:Settings:Message* | *Data from Azure App Configuration - now with live updates!* |
188-
| *TestApp:Settings:Sentinel* | *v2* |
189187

190188
1. Refresh the browser page to see the new configuration settings. You may need to refresh more than once for the changes to be reflected or change your cache expiration time to less than 5 minutes.
191189

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-background-service.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
8686
{
8787
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
8888
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
89-
// Load all keys that start with `TestApp:`.
89+
// Load all keys that start with `TestApp:` and have no label.
9090
.Select("TestApp:*")
91-
// Configure to reload the key 'TestApp:Settings:Message' if it is modified.
91+
// Reload configuration if any selected key-values have changed.
9292
.ConfigureRefresh(refreshOptions =>
9393
{
94-
refreshOptions.Register("TestApp:Settings:Message");
94+
refreshOptions.RegisterAll();
9595
});
9696
9797
// Register the refresher so that the Worker service can consume it through DI
@@ -112,12 +112,12 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
112112
builder.Configuration.AddAzureAppConfiguration(options =>
113113
{
114114
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
115-
// Load all keys that start with `TestApp:`.
115+
// Load all keys that start with `TestApp:` and have no label.
116116
.Select("TestApp:*")
117-
// Configure to reload the key 'TestApp:Settings:Message' if it is modified.
117+
// Reload configuration if any selected key-values have changed.
118118
.ConfigureRefresh(refreshOptions =>
119119
{
120-
refreshOptions.Register("TestApp:Settings:Message");
120+
refreshOptions.RegisterAll();
121121
});
122122
123123
// Register the refresher so that the Worker service can consume it through DI
@@ -129,7 +129,10 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
129129
```
130130
---
131131
132-
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `Register` method has an optional boolean parameter `refreshAll` that can be used to indicate whether all configuration values should be refreshed if the registered key changes. In this example, only the key *TestApp:Settings:Message* will be refreshed. All settings registered for refresh have a default cache expiration of 30 seconds before a new refresh is attempted. It can be updated by calling the `AzureAppConfigurationRefreshOptions.SetRefreshInterval` method.
132+
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload the entire configuration whenever it detects a change in any of the selected key-values (those starting with *TestApp:* and having no label). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
133+
134+
> [!TIP]
135+
> You can add a call to the `refreshOptions.SetRefreshInterval` method to specify the minimum time between configuration refreshes. In this example, you use the default value of 30 seconds. Adjust to a higher value if you need to reduce the number of requests made to your App Configuration store.
133136
134137
1. Open *Worker.cs*. Inject `IConfiguration` and `IConfigurationRefresher` to the `Worker` service and log the configuration data from App Configuration.
135138

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-core-push-refresh.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ namespace TestConsole
108108
.AddAzureAppConfiguration(options =>
109109
{
110110
options.Connect(appConfigurationConnectionString);
111+
// Load the key-value with key "TestApp:Settings:Message" and no label
112+
options.Select("TestApp:Settings:Message");
113+
// Reload configuration if any selected key-values have changed.
111114
options.ConfigureRefresh(refresh =>
112115
refresh
113-
.Register("TestApp:Settings:Message")
116+
.RegisterAll()
114117
// Important: Reduce poll frequency
115118
.SetRefreshInterval(TimeSpan.FromDays(1))
116119
);
@@ -170,7 +173,7 @@ namespace TestConsole
170173
}
171174
```
172175

173-
The `ProcessPushNotification` method resets the cache expiration to a short random delay. This causes future calls to `RefreshAsync` or `TryRefreshAsync` to re-validate the cached values against App Configuration and update them as necessary. In this example you register to monitor changes to the key: *TestApp:Settings:Message* with a cache expiration of one day. This means no request to App Configuration will be made before a day has passed since the last check. By calling `ProcessPushNotification` your application will send requests to App Configuration in the next few seconds. Your application will load the new configuration values shortly after changes occur in the `App Configuration` store without the need to constantly poll for updates. In case your application misses the change notification for any reason, it will still check for configuration changes once a day.
176+
The `ProcessPushNotification` method resets the cache expiration to a short random delay. This causes future calls to `RefreshAsync` or `TryRefreshAsync` to re-validate the cached values against App Configuration and update them as necessary. In this example you register to monitor changes to all selected key-values (*TestApp:Settings:Message*) with a cache expiration of one day. This means no request to App Configuration will be made before a day has passed since the last check. By calling `ProcessPushNotification` your application will send requests to App Configuration in the next few seconds. Your application will load the new configuration values shortly after changes occur in the `App Configuration` store without the need to constantly poll for updates. In case your application misses the change notification for any reason, it will still check for configuration changes once a day.
174177

175178
The short random delay for cache expiration is helpful if you have many instances of your application or microservices connecting to the same App Configuration store with the push model. Without this delay, all instances of your application could send requests to your App Configuration store simultaneously as soon as they receive a change notification. This can cause the App Configuration Service to throttle your store. Cache expiration delay is set to a random number between 0 and a maximum of 30 seconds by default, but you can change the maximum value through the optional parameter `maxDelay` to the `ProcessPushNotification` method.
176179

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-core.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ var builder = new ConfigurationBuilder();
4646
builder.AddAzureAppConfiguration(options =>
4747
{
4848
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
49+
// Load the key-value with key "TestApp:Settings:Message" and no label
50+
.Select("TestApp:Settings:Message")
51+
// Reload configuration if any selected key-values have changed.
4952
.ConfigureRefresh(refresh =>
5053
{
51-
refresh.Register("TestApp:Settings:Message")
54+
refresh.RegisterAll()
5255
.SetRefreshInterval(TimeSpan.FromSeconds(10));
5356
});
5457

@@ -70,7 +73,9 @@ if (_refresher != null)
7073
}
7174
```
7275

73-
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `Register` method has an optional boolean parameter `refreshAll` that can be used to indicate whether all configuration values should be refreshed if the registered key changes. In this example, only the key *TestApp:Settings:Message* will be refreshed. The `SetRefreshInterval` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 10 seconds instead for demonstration purposes.
76+
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload the entire configuration whenever it detects a change in any of the selected key-values (in this case, just *TestApp:Settings:Message*). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
77+
78+
The `SetRefreshInterval` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 10 seconds instead for demonstration purposes.
7479

7580
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method from the interface `IConfigurationRefresher` to trigger a refresh. This design is to avoid requests sent to App Configuration even when your application is idle. You'll want to include the `TryRefreshAsync` call where you consider your application active. For example, it can be when you process an incoming message, an order, or an iteration of a complex task. It can also be in a timer if your application is active all the time. In this example, you call `TryRefreshAsync` every time you press the Enter key. Even if the call `TryRefreshAsync` fails for any reason, your application continues to use the cached configuration. Another attempt is made when the configured cache expiration time has passed and the `TryRefreshAsync` call is triggered by your application activity again. Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal, even if it's called frequently.
7681

0 commit comments

Comments
 (0)