azure - 尝试监听 Azure 事件中心时出现未经授权的错误

标签 azure azure-eventhub

我有一个简单的 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();
    }
}

}

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

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

最佳答案

错误消息非常具有 self 描述性。确保 SharedAccessKeyName SendETB 允许“监听”权限。您可以在门户网站上进行检查,如下所示。

enter image description here

关于azure - 尝试监听 Azure 事件中心时出现未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59939707/

相关文章:

asp.net-mvc - 增加 Azure Web 应用程序请求超时

java - Storm : eventhub spout stops receiving messages

python - 使用 python 在 Azure Event Hub 中收集 Websocket 流数据

azure - Azure Functions 事件中心检查点是否适用于多个实例?

c# - Azure Web应用程序授权: session variables for auth/me

visual-studio - 如何使用 Visual Studio 调整 Azure Functions 2.0 上的图像大小?

Azure 诊断日志保存到另一个位置

wcf - 计算 WCF 服务操作发送的总字节数

azure - 使用 AMQP 建立与事件中心的连接时如何设置 x-opt-offset 以避免消息重播