Last active
February 17, 2020 08:51
-
-
Save danigian/d6d81d1956241ede578c951a6cd0d747 to your computer and use it in GitHub Desktop.
ServiceBus authentication with Managed Identities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async Task ServiceBusTest() | |
{ | |
// Managed identity needs "Azure Service Bus Data Owner" role assigned and scoped to ServiceBus | |
var tokenProvider = Microsoft.Azure.ServiceBus.Primitives.TokenProvider.CreateManagedIdentityTokenProvider(); | |
TopicClient topicSendClient = new TopicClient($"sb://{sbNamespace}.servicebus.windows.net/", sbEntity, tokenProvider, Microsoft.Azure.ServiceBus.TransportType.Amqp, null); | |
await topicSendClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello world from Managed Identity"))); | |
await topicSendClient.CloseAsync(); | |
Console.WriteLine($"Message sent to {sbNamespace}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="4.1.1" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment