【发布时间】: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