Skip to content

Commit 934ec3f

Browse files
update
1 parent eec0342 commit 934ec3f

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-javascript.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
9292
```javascript
9393
// Polling for configuration changes every 5 seconds
9494
while (true) {
95-
await sleepInMs(5000); // Waiting before the next refresh
96-
await appConfig.refresh(); // Refreshing the configuration setting
9795
console.log(appConfig.get("message")); // Consume current value of message from a Map
96+
appConfig.refresh(); // Refreshing the configuration setting asynchronously
97+
await sleepInMs(5000); // Waiting before the next refresh
9898
}
9999
```
100100

@@ -103,9 +103,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
103103
```javascript
104104
// Polling for configuration changes every 5 seconds
105105
while (true) {
106-
await sleepInMs(5000); // Waiting before the next refresh
107-
await appConfig.refresh(); // Refreshing the configuration setting
108106
console.log(config.message); // Consume current value of message from an object
107+
appConfig.refresh(); // Refreshing the configuration setting asynchronously
108+
await sleepInMs(5000); // Waiting before the next refresh
109109
}
110110
```
111111

@@ -133,9 +133,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
133133
134134
// Polling for configuration changes every 5 seconds
135135
while (true) {
136-
await sleepInMs(5000); // Waiting before the next refresh
137-
await appConfig.refresh(); // Refreshing the configuration setting
138136
console.log(appConfig.get("message")); // Consume current value of message from a Map
137+
appConfig.refresh(); // Refreshing the configuration setting asynchronously
138+
await sleepInMs(5000); // Waiting before the next refresh
139139
}
140140
}
141141
@@ -170,9 +170,9 @@ You can connect to App Configuration using either Microsoft Entra ID (recommende
170170
171171
// Polling for configuration changes every 5 seconds
172172
while (true) {
173-
await sleepInMs(5000); // Waiting before the next refresh
174-
await appConfig.refresh(); // Refreshing the configuration setting
175173
console.log(config.message); // Consume current value of message from an object
174+
appConfig.refresh(); // Refreshing the configuration setting asynchronously
175+
await sleepInMs(5000); // Waiting before the next refresh
176176
}
177177
}
178178

articles/azure-app-configuration/reference-javascript-provider.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const settings = await load(endpoint, credential, {
211211

212212
Setting up `refreshOptions` alone won't automatically refresh the configuration. You need to call the `refresh` method on `AzureAppConfiguration` instance returned by the `load` method to trigger a refresh.
213213

214-
``` typescript
214+
```typescript
215215
// this call is not blocking, the configuration will be updated asynchronously
216216
settings.refresh();
217217
```
@@ -229,6 +229,42 @@ server.use((req, res, next) => {
229229

230230
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.
231231

232+
### Custom refresh callback
233+
234+
The `onRefresh` method lets you custom callback functions that will be invoked each time the local configuration is successfully updated with changes from the Azure App Configuration store. It returns a Disposable object, which you can use to remove the registered callback
235+
236+
```typescript
237+
const settings = await load(endpoint, credential, {
238+
refreshOptions: {
239+
enabled: true
240+
}
241+
});
242+
const disposer = settings.onRefresh(() => {
243+
console.log("Config refreshed.");
244+
});
245+
246+
settings.refresh();
247+
// Once the refresh is successful, the callback function you registered will be executed.
248+
// In this example, the message "Config refreshed" will be printed.
249+
250+
disposer.dispose();
251+
```
252+
253+
### Refresh on sentinel key (Legacy)
254+
255+
A sentinel key is a key that you update after you complete the change of all other keys. The configuration provider will monitor the sentinel key instead of all selected key-values. When a change is detected, your app refreshes all configuration values.
256+
257+
```typescript
258+
const settings = await load(endpoint, credential, {
259+
refreshOptions: {
260+
enabled: true,
261+
watchedSettings: [
262+
{ key: "sentinel" }
263+
]
264+
}
265+
});
266+
```
267+
232268
For more information about refresh configuration, go to [Use dynamic configuration in JavaScript](./enable-dynamic-configuration-javascript.md).
233269

234270
## Feature flag
@@ -241,7 +277,7 @@ const settings = await load(endpoint, credential, {
241277
enabled: true,
242278
selectors: [ { keyFilter: "*", labelFilter: "Prod" } ],
243279
refresh: {
244-
enabled: true,
280+
enabled: true, // the refresh for feature flags need to be enbaled in addition to key-values
245281
refreshIntervalInMs: 10_000
246282
}
247283
}

0 commit comments

Comments
 (0)