Raas Masood
Raas Masood

Reputation: 1575

getting unauthorized error trying to listen to Azure Event Hub

i have a simple EventHub listener sample code trying to listen to event hub

public class Program
{



    private const string EventHubConnectionString = "Endpoint=sb://fake.servicebus.windows.net/;SharedAccessKeyName=SendETB;SharedAccessKey=JcvVeX5KsGHfJkPNmdns5jvNYVpB9Wc05jDuMaV3NW8=";
    private const string EventHubName = "myhub";
    private const string StorageContainerName = "my-own-container";
    private const string StorageAccountName = "mystorage";
    private const string StorageAccountKey = "fakeZn8WUV1mcsh0MVbmea/ypxDs+No2tzrhr0kUmjxvA0a0jUxfZ29hHoY/yopVvGLEn/stEQbBEAyjYMX9g==";



    private static readonly string StorageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, StorageAccountKey);

    public static void Main(string[] args)
    {
        MainAsync(args).GetAwaiter().GetResult();
    }

    private static async Task MainAsync(string[] args)
    {
        Console.WriteLine("Registering EventProcessor...");

        var eventProcessorHost = new EventProcessorHost(
            EventHubName,
            PartitionReceiver.DefaultConsumerGroupName,
            EventHubConnectionString,
            StorageConnectionString,
            StorageContainerName);

        // Registers the Event Processor Host and starts receiving messages
        await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();

        Console.WriteLine("Receiving. Press enter key to stop worker.");
        Console.ReadLine();

        // Disposes of the Event Processor Host
        await eventProcessorHost.UnregisterEventProcessorAsync();
    }
}

}

with the above mentioned code i get an error.

Error on Partition: 0, Error: Unauthorized access. 'Listen' claim(s) are required to perform this operation. Resource: 'sb://fake.servicebus.windows.net/etbhub/consumergroups/$default/partitions/0'. TrackingId:fakef417d94238ba36d41d32b83341_G9, SystemTracker:gateway5, Timestamp:2020-01-27T22:06:49

Upvotes: 2

Views: 4494

Answers (2)

Ganesh Todkar
Ganesh Todkar

Reputation: 537

Make sure you have added a Shared Access Policy for Listen for your Event Hub Namespace.

For Event Hub it should be Send

For Event Hub Namespace it should have all three Manage, Sen, Listen as per the need.

Upvotes: 0

Serkant Karaca
Serkant Karaca

Reputation: 2042

Error message is pretty self-descriptive. Make sure SharedAccessKeyName SendETB allows 'Listen' permission. You can check it on the portal like below.

enter image description here

Upvotes: 2

Related Questions