You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/enable-dynamic-configuration-javascript.md
+14-39Lines changed: 14 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ Before you continue, finish [Create a JavaScript app with Azure App Configuratio
21
21
## Prerequisites
22
22
23
23
- Finish the quickstart [Create a JavaScript app with Azure App Configuration](./quickstart-javascript-provider.md).
24
+
- Update the [`@azure/app-configuration-provider`](https://www.npmjs.com/package/@azure/app-configuration-provider) package to version **2.0.0** or later.
24
25
25
26
## Add key-values
26
27
@@ -29,12 +30,6 @@ Add the following key-value to your Azure App Configuration store. For more info
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 Azure App Configuration store, compared to monitoring all keys for changes.
35
-
36
-
> [!NOTE]
37
-
> If you use version **2.0.0-preview.2** or later of [@azure/app-configuration-provider](https://www.npmjs.com/package/@azure/app-configuration-provider), the App Configuration provider will by default refresh based on monitoring the key-value collection. Sentinel key is not needed for refresh. For more information, please go to [Monitor key-value collection for refresh](#monitor-key-value-collection-for-refresh)
38
33
39
34
## Console applications
40
35
@@ -52,10 +47,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
52
47
```javascript
53
48
// Connecting to Azure App Configuration using endpoint and token credential
54
49
constappConfig=awaitload(endpoint, credential, {
55
-
//Setting up to refresh when the sentinel key is changed
50
+
//Enabling the dynamic refresh
56
51
refreshOptions: {
57
-
enabled:true,
58
-
watchedSettings: [{ key:"sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
52
+
enabled:true
59
53
}
60
54
});
61
55
```
@@ -68,10 +62,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
68
62
```javascript
69
63
// Connecting to Azure App Configuration using endpoint and token credential
//Setting up to refresh when the sentinel key is changed
65
+
//Enabling the dynamic refresh
72
66
refreshOptions: {
73
-
enabled:true,
74
-
watchedSettings: [{ key:"sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
67
+
enabled:true
75
68
}
76
69
});
77
70
@@ -86,6 +79,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
86
79
```
87
80
---
88
81
82
+
> [!NOTE]
83
+
> If you get the error:"Refresh is enabled but no watched settings are specified.", please update the [`@azure/app-configuration-provider`](https://www.npmjs.com/package/@azure/app-configuration-provider) package to version **2.0.0** or later.
84
+
89
85
1. Setting up `refreshOptions` alone won't automatically refresh the configuration. You need to call the `refresh` method to trigger a refresh. This design prevents unnecessary requests to App Configuration when your application is idle. You should include the `refresh` call where your application activity occurs. This is known as **activity-driven configuration refresh**. For example, you can call `refresh` when processing an incoming message or an order, or inside an iteration where you perform a complex task. Alternatively, you can use a timer if your application is always active. In this example, `refresh` is called in a loop for demonstration purposes. Even if the `refresh` call fails for any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured refresh interval has passed and the `refresh` call is triggered by your application activity. Calling `refresh` is a no-op before the configured refresh interval elapses, so its performance impact is minimal even if it's called frequently.
90
86
91
87
Add the following code to poll configuration changes of watched key-values.
@@ -128,10 +124,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
128
124
async function run() {
129
125
// Connecting to Azure App Configuration using endpoint and token credential
|*message*|*Hello World - Updated!*| Leave empty | Leave empty |
208
-
|*sentinel*|*2*| Leave empty | Leave empty |
209
202
210
203
1. Once the values are updated, the updated value is printed after the refresh interval.
211
204
212
205
```console
213
206
Hello World - Updated!
214
207
```
215
208
216
-
## Monitor key-value collection for refresh
217
-
218
-
Instead of monitoring any sentinel key, the App Configuration provider supports for monitoring all selected key-values. Configuration will be refreshed if any of key-values are updated. Watching the sentinel key for refresh helps ensure data integrity of configuration changes, but it is now optional. This behavior is activated when you enable the refresh but do not specify any watched keys in`AzureAppConfigurationOptions.refreshOptions`
appConfig.refresh(); // Configuration will be refreshed if any of key-values are updated.
229
-
```
230
-
231
-
This feature is available for version **2.0.0-preview.2** or later of [@azure/app-configuration-provider](https://www.npmjs.com/package/@azure/app-configuration-provider).
232
-
233
209
## Server application
234
210
235
211
The following example shows how to update an existing http server to use refreshable configuration values.
@@ -284,8 +260,7 @@ The following example shows how to update an existing http server to use refresh
284
260
appConfig = await load(endpoint, credential, {
285
261
refreshOptions: {
286
262
enabled: true,
287
-
// without registering any watched setting/sentinel key, the provider will monitor the key-value collection for refresh
288
-
refreshIntervalInMs: 15_000 // Set the refresh interval
263
+
refreshIntervalInMs: 15_000 // set the refresh interval
0 commit comments