Unable to connect to event hub using TokenCredential

Madeline Stager 31 Reputation points
2022-07-07T18:55:48.767+00:00

When attempting to connect to event hub using token credentials I get a timeout from the cancelation token and no response from the event hub service. Sample bellow shows trying to get the event hub properties, I saw the same behavior when trying to send events to event hub. I tried using MSI credentials as in the sample bellow as well as my Azure identity credentials using InteractiveBrowserCredential. When using the InteractiveBrowserCredential, I was prompted for my credentials and entered them, and then received a token cancelation exception after some time. I have testing using Azure.Messaging.EventHubs and Azure.Messaging.EventHubs.Producer .net SDK version 5.7.0 and 5.7.1.

How can I connect to event hub using MSI?

string ednpoint = "{EventHubInstanceName}.servicebus.windows.net";
string eventHubName = "sessionqueue";
string msiClientId = "{MSIClientId}";
var creds= new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = msiClientId });
var eventHubClient = new EventHubProducerClient(ednpoint, eventHubName, creds);

using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)))
{
var properties = await eventHubClient.GetEventHubPropertiesAsync(cts.Token).ConfigureAwait(false);
}

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
558 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,549 questions
{count} vote