Skip to content

Commit de2e415

Browse files
author
Anders Tøgersen (Delegate)
committed
Updated SampleApi and README
1 parent 9995d5e commit de2e415

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

Atc.Azure.Messaging.sln

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Azure.Messaging", "src\
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Azure.Messaging.Tests", "test\Atc.Azure.Messaging.Tests\Atc.Azure.Messaging.Tests.csproj", "{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}"
99
EndProject
10-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5F9CEB97-F31C-493F-9FF4-EF94F8169B80}"
11-
ProjectSection(SolutionItems) = preProject
12-
version.json = version.json
13-
EndProjectSection
14-
EndProject
1510
Global
1611
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1712
Debug|Any CPU = Debug|Any CPU

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@ builder.Services.AddSwaggerGen();
3737
builder.Services.ConfigureMessagingServices(builder.Configuration);
3838
```
3939

40+
## Connecting with Managed Identity
41+
42+
When connecting with Managed Identity you need to setup your configuration accordingly.
43+
44+
The following is an example of how you would configure your EventHub or ServiceBus with Managed Identity for [ATC Azure Options](https://github.com/atc-net/atc-azure-options)
45+
46+
```json
47+
{
48+
"EventHubOptions": {
49+
"FullyQualifiedNamespace": "[your eventhub namespace].servicebus.windows.net"
50+
},
51+
"ServiceBusOptions": {
52+
"FullyQualifiedNamespace": "[your servicebus namespace].servicebus.windows.net"
53+
},
54+
"ClientAuthorizationOptions": {
55+
"TenantId": "[your tenant id]"
56+
},
57+
"EnvironmentOptions": {
58+
"EnvironmentType": "[Local/DevTest/Production]"
59+
}
60+
}
61+
```
62+
63+
It is important that the logged-in user/application has the `Azure Service Bus Data Sender` or `Azure Service Bus Data Owner` build-in role for [ServiceBus](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-managed-service-identity#azure-built-in-roles-for-azure-service-bus).
64+
65+
And the corresponding `Azure Event Hubs Data Sender` or `Azure Event Hubs Data Owner` build-in roles for [Eventhubs](https://learn.microsoft.com/en-us/azure/event-hubs/authenticate-application#built-in-roles-for-azure-event-hubs)
66+
67+
The dependencies are registered using `ConfigureMessagingServices(IConfiguration, bool)` for the default implementation of [IAzureCredentialOptionsProvider](https://github.com/atc-net/atc-azure-options/blob/main/src/Atc.Azure.Options/Providers/AzureCredentialOptionsProvider.cs) and `ConfigureMessagingServices(IConfiguration, bool, IAzureCredentialOptionsProvider)` if you wish to use your own implementation of `IAzureCredentialOptionsProvider`.
68+
69+
Here's an example of the default implementation using a Minimal API setup
70+
71+
```csharp
72+
var builder = WebApplication.CreateBuilder(args);
73+
builder.Services.AddEndpointsApiExplorer();
74+
builder.Services.AddSwaggerGen();
75+
76+
// Register Atc.Azure.Messaging dependencies
77+
builder.Services.ConfigureMessagingServices(builder.Configuration, true);
78+
```
79+
4080
## Publishing to EventHub
4181

4282
To publish events to an EventHub you need an instance of `IEventHubPublisher`, this can be constructed via the `IEventHubPublisherFactory` which exposes the `Create(string eventHubName)` method

sample/SampleApi/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
builder.Services.AddSingleton<SendDataHandler>();
1313

1414
// Register Atc.Azure.Messaging dependencies
15-
builder.Services.ConfigureMessagingServices(builder.Configuration);
15+
builder.Services.ConfigureMessagingServices(builder.Configuration); // ConfigureMessagingServices(builder.Configuration, true)
1616

1717
var app = builder.Build();
1818
app.UseHttpsRedirection();
@@ -38,15 +38,14 @@ public SendDataHandler(
3838
IEventHubPublisherFactory eventHubFactory,
3939
IServiceBusPublisher serviceBusPublisher)
4040
{
41-
eventHubPublisher = eventHubFactory.Create("[existing eventhub");
41+
eventHubPublisher = eventHubFactory.Create("[existing eventhub]");
4242
this.serviceBusPublisher = serviceBusPublisher;
4343
}
4444

4545
public async Task<Response> Post(Request request)
4646
{
4747
await eventHubPublisher.PublishAsync(request);
48-
49-
await serviceBusPublisher.PublishAsync("existing topic|queue", request);
48+
await serviceBusPublisher.PublishAsync("[existing topic|queue]", request);
5049

5150
return new Response(
5251
Guid.NewGuid().ToString("N"),

sample/SampleApi/appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@
88
"AllowedHosts": "*",
99
"EventHubOptions": {
1010
"ConnectionString": "Endpoint=sb://[your eventhub namespace].servicebus.windows.net/;SharedAccessKeyName=[eventhub name];SharedAccessKey=[sas key]"
11+
},
12+
"ServiceBusOptions": {
13+
"FullyQualifiedNamespace": "[your servicebus namespace].servicebus.windows.net"
14+
},
15+
"ClientAuthorizationOptions": {
16+
"TenantId": "[your tenant id]"
17+
},
18+
"EnvironmentOptions": {
19+
"EnvironmentType": "Local"
1120
}
1221
}

0 commit comments

Comments
 (0)