VitoldUSA
VitoldUSA

Reputation: 57

.NET SDK Azure EventHub - Authenticating Consumer/Receiver using Active Directory Client Id and Secret Value

Can some one provide a .NET C# sample on how to instantiate EventProcessorClient object as a RECEIVER using Azure's Active Directory RBAC using TenantID, Client ID and Secret ?

I would like to build a consumer piece which access a single partition in Event Hub.

I have searched the earth and there is not event a single example which explains that. The articles i did find only uses SAS Connection String approach.

using Azure.Messaging.EventHubs.Processor 5.4.1 Thanks

Upvotes: 0

Views: 466

Answers (1)

Serkant Karaca
Serkant Karaca

Reputation: 2032

Here is a small snippet as a starting point for you. EventProcessorClient also takes TokenCredential as a parameter so it should also work in a similar way.

TokenCredential credential = new ClientSecretCredential("<tenant-id>", "<client-id>", "<client-secret>");
var fullyQualifiedNamespace = "<ehnamespace>.servicebus.windows.net";
var eventHubName = "<eventhubname>";
var consumerGroup = "<consumergroupname";

var consumer = new EventHubConsumerClient(
                consumerGroup,
                fullyQualifiedNamespace,
                eventHubName,
                credential);

Upvotes: 1

Related Questions