Skip to content

Commit 7186086

Browse files
authored
Merge pull request #122221 from artemious7/patch-12
Fix code in enable-dynamic-configuration-dotnet-core-push-refresh.md
2 parents 56942fb + 0364a6a commit 7186086

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ In this tutorial, you learn how to:
3939

4040
## Set up Azure Service Bus topic and subscription
4141

42-
This tutorial uses the Service Bus integration for Event Grid to simplify the detection of configuration changes for applications that don't wish to poll App Configuration for changes continuously. The Azure Service Bus SDK provides an API to register a message handler that can be used to update configuration when changes are detected in App Configuration. Follow steps in the [Quickstart: Use the Azure portal to create a Service Bus topic and subscription](../service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal.md) to create a service bus namespace, topic, and subscription.
42+
This tutorial uses the Service Bus integration for Event Grid to simplify the detection of configuration changes for applications that don't wish to poll App Configuration for changes continuously. The Azure Service Bus SDK provides an API to register a message handler that can be used to update configuration when changes are detected in App Configuration. Follow the steps in the [Quickstart: Use the Azure portal to create a Service Bus topic and subscription](../service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal.md) to create a service bus namespace, topic, and subscription.
4343

4444
Once the resources are created, add the following environment variables. These will be used to register an event handler for configuration changes in the application code.
4545

@@ -111,13 +111,14 @@ namespace TestConsole
111111
options.ConfigureRefresh(refresh =>
112112
refresh
113113
.Register("TestApp:Settings:Message")
114-
.SetCacheExpiration(TimeSpan.FromDays(1)) // Important: Reduce poll frequency
114+
// Important: Reduce poll frequency
115+
.SetCacheExpiration(TimeSpan.FromDays(1))
115116
);
116117

117118
_refresher = options.GetRefresher();
118119
}).Build();
119120

120-
RegisterRefreshEventHandler();
121+
await RegisterRefreshEventHandler();
121122
var message = configuration["TestApp:Settings:Message"];
122123
Console.WriteLine($"Initial value: {configuration["TestApp:Settings:Message"]}");
123124

@@ -135,33 +136,35 @@ namespace TestConsole
135136
}
136137
}
137138

138-
private static void RegisterRefreshEventHandler()
139+
private static async Task RegisterRefreshEventHandler()
139140
{
140141
string serviceBusConnectionString = Environment.GetEnvironmentVariable(ServiceBusConnectionStringEnvVarName);
141142
string serviceBusTopic = Environment.GetEnvironmentVariable(ServiceBusTopicEnvVarName);
142-
string serviceBusSubscription = Environment.GetEnvironmentVariable(ServiceBusSubscriptionEnvVarName);
143+
string serviceBusSubscription = Environment.GetEnvironmentVariable(ServiceBusSubscriptionEnvVarName);
143144
ServiceBusClient serviceBusClient = new ServiceBusClient(serviceBusConnectionString);
144145
ServiceBusProcessor serviceBusProcessor = serviceBusClient.CreateProcessor(serviceBusTopic, serviceBusSubscription);
145146

146147
serviceBusProcessor.ProcessMessageAsync += (processMessageEventArgs) =>
147-
{
148-
// Build EventGridEvent from notification message
149-
EventGridEvent eventGridEvent = EventGridEvent.Parse(BinaryData.FromBytes(processMessageEventArgs.Message.Body));
148+
{
149+
// Build EventGridEvent from notification message
150+
EventGridEvent eventGridEvent = EventGridEvent.Parse(BinaryData.FromBytes(processMessageEventArgs.Message.Body));
150151

151-
// Create PushNotification from eventGridEvent
152-
eventGridEvent.TryCreatePushNotification(out PushNotification pushNotification);
152+
// Create PushNotification from eventGridEvent
153+
eventGridEvent.TryCreatePushNotification(out PushNotification pushNotification);
153154

154-
// Prompt Configuration Refresh based on the PushNotification
155-
_refresher.ProcessPushNotification(pushNotification);
155+
// Prompt Configuration Refresh based on the PushNotification
156+
_refresher.ProcessPushNotification(pushNotification);
156157

157-
return Task.CompletedTask;
158-
};
158+
return Task.CompletedTask;
159+
};
159160

160161
serviceBusProcessor.ProcessErrorAsync += (exceptionargs) =>
161-
{
162-
Console.WriteLine($"{exceptionargs.Exception}");
163-
return Task.CompletedTask;
164-
};
162+
{
163+
Console.WriteLine($"{exceptionargs.Exception}");
164+
return Task.CompletedTask;
165+
};
166+
167+
await serviceBusProcessor.StartProcessingAsync();
165168
}
166169
}
167170
}

0 commit comments

Comments
 (0)