【问题标题】:getting unauthorized error trying to listen to Azure Event Hub尝试侦听 Azure 事件中心时出现未经授权的错误
【发布时间】:2020-05-13 08:01:54
【问题描述】:

我有一个简单的 EventHub 监听器示例代码尝试监听事件中心

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();
    }
}

}

使用上面提到的代码我得到一个错误。

分区错误:0,错误:未经授权的访问。执行此操作需要“侦听”声明。资源:'sb://fake.servicebus.windows.net/etbhub/consumergroups/$default/partitions/0'。 TrackingId:fakef417d94238ba36d41d32b83341_G9, SystemTracker:gateway5, Timestamp:2020-01-27T22:06:49

【问题讨论】:

    标签: azure azure-eventhub


    【解决方案1】:

    错误信息非常具有自我描述性。确保 SharedAccessKeyName SendETB 允许“侦听”权限。您可以在门户网站上查看,如下所示。

    【讨论】:

      【解决方案2】:

      确保您为 Event Hub 命名空间添加了 Listen 共享访问策略。

      对于事件中心,它应该是发送

      对于事件中心命名空间,它应该根据需要具有所有三个 Manage、Sen、Listen。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-28
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-19
        相关资源
        最近更新 更多