Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 98cc0e2

Browse files
feat: add managed identity support auto-refresh app config job (#159)
* feat: add managed identity support auto-refresh app config job * Update docs/preview/02-Features/05-AzureAppConfiguration/auto-refresh-app-configuration.md Co-authored-by: Frederik Gheysels <[email protected]> Co-authored-by: Frederik Gheysels <[email protected]>
1 parent 36fdcbf commit 98cc0e2

File tree

4 files changed

+645
-85
lines changed

4 files changed

+645
-85
lines changed

docs/preview/02-Features/05-AzureAppConfiguration/auto-refresh-app-configuration.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,62 @@ We use the events from Azure App Configuration which will be send towards an Azu
2121
2. Create an Azure Service Bus Topic resource
2222
3. Create an event subscription on the App Configuration resource to send events to the Service Bus Topic
2323

24-
25-
2624
![Automatically refresh Azure App Configuration values](/media/Azure-App-Configuration-Job.png)
2725

2826
Both the connection string of the Azure App Configuration and the Azure Service Bus Topic will be needed in the next section, so make sure you have those.
2927

30-
## Usage
31-
Our background job requires both the configuration of Azure App Configuration while setting up the `IConfiguration`,
28+
## Usage with managed identity
29+
When connecting to Azure App Configuration using managed identity, you only need to provide the Azure Service Bus topic name and namespace where the Azure App Configuration events are placed:
30+
31+
```csharp
32+
using Microsoft.Extensions.DependencyInjection;
33+
using Microsoft.Extensions.Hosting;
34+
35+
public class Program
36+
{
37+
public static void Main(string[] args)
38+
{
39+
IHostBuilder hostBuilder = CreateHostBuilder(args);
40+
hostBuilder.Build().Run();
41+
}
42+
43+
private static IHostBuilder CreateHostBuilder(string[] args)
44+
{
45+
return Host.CreateDefaultBuilder(args)
46+
.ConfigureAppConfiguration(configBuilder => ConfigureAppConfiguration(configBuilder))
47+
.ConfigureServices(services => ConfigureServices(services));
48+
}
49+
50+
private static void ConfigureAppConfiguration(IConfigurationBuilder configBuilder)
51+
{
52+
configBuilder.AddAzureAppConfiguration(appConfigOptions =>
53+
{
54+
appConfigOptions.Connect("<your-azure-app-configuration-endpoint>", new ManagedIdentityCredential())
55+
// Specifies which Azure App Configuration key you want to automatically updated.
56+
.Register("<your-azure-app-configuration-key>");
57+
});
58+
}
59+
60+
public void ConfigureServices(IServiceCollection services)
61+
{
62+
// Adds the automatic Azure App Configuration refresh background job
63+
services.AddAutoRefreshAppConfigurationBackgroundJobUsingManagedIdentity(
64+
// The name of the Azure Service Bus topic where Azure App Configuration events are placed.
65+
topicName: "<servicebus-topic-name>",
66+
// The namespace of the Azure Service Bus topic where Azure App Configuration events are placed.
67+
serviceBusNamespace: "<your-namespace>.servicebus.windows.net",
68+
// Prefix of the Azure Service Bus Topic subscription;
69+
// this allows the background jobs to support applications that are running multiple instances, processing the same type of events, without conflicting subscription names.
70+
subscriptionPrefix: "TestSub",
71+
// The client ID to authenticate for a user assigned managed identity. More information on user assigned managed identities cam be found here:
72+
// https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vm.
73+
clientId: null);
74+
}
75+
}
76+
```
77+
78+
## Usage with connection string
79+
When using a connection string to connect to Azure App Configuration, our background job requires both the configuration of Azure App Configuration while setting up the `IConfiguration`,
3280
as well as the [Arcus secret store](https://security.arcus-azure.net/features/secret-store) which will retrieve the connection string of the Azure Service Bus Topic.
3381

3482
```csharp
@@ -76,4 +124,6 @@ public class Program
76124
}
77125
```
78126

79-
[&larr; back](/)
127+
## Configuration
128+
The background job provides configuration options to alter the behavior of the internal message pump that processes the Azure App Configuration events.
129+
These messaging options are explained in detail at the [Arcus messaging feature documentation](https://messaging.arcus-azure.net/Features/message-pumps/service-bus#configuration).

0 commit comments

Comments
 (0)