代码之家  ›  专栏  ›  技术社区  ›  Raas Masood

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

  •  0
  • Raas Masood  · 技术社区  · 6 年前

    我有一个简单的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/distributes/0”。跟踪ID:fakef417d94238ba36d41d32b83341_G9,系统跟踪器:网关5,时间戳:2020-01-27T22:06:49

    1 回复  |  直到 6 年前
        1
  •  2
  •   Serkant Karaca    6 年前

    错误消息非常自我描述。确保SharedAccessKeyName SendETB允许“监听”权限。你可以在下面的门户网站上查看。

    enter image description here

        2
  •  0
  •   Ganesh Todkar    5 年前

    确保您已为添加了共享访问策略 听 为您的 事件中心命名空间 .

    对于Event Hub,它应该是Send

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