【问题标题】:Event Hub Resource not found找不到事件中心资源
【发布时间】:2020-08-27 13:19:53
【问题描述】:

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send

我正在关注有关事件中心的教程,但在使用完全相同的代码连接到事件网格时遇到问题。 有没有人遇到过类似的问题?

namespace EventHub
{
    class Program
    {
        private const string connectionString = "Endpoint=sb://emailsevents.servicebus.windows.net/;SharedAccessKeyName=randomaccess;SharedAccessKey=<my_key>";
        private const string eventHubName = "emailsevents.servicebus.windows.net";
        private static async Task Main()
        {
            // Create a producer client that you can use to send events to an event hub
            await using (var producerClient = new EventHubProducerClient(connectionString, eventHubName))
            {
                // Create a batch of events 
                using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
                // Add events to the batch. An event is a represented by a collection of bytes and metadata. 
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("First event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Second event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Third event")));
                // Use the producer client to send the batch of events to the event hub
                await producerClient.SendAsync(eventBatch);
                Console.WriteLine("A batch of 3 events has been published.");
            }
        }
    }
}

我收到了Unhandled exception. EventHubsException(ResourceNotFound) 当我打线时

        using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();

【问题讨论】:

    标签: azure azure-eventhub


    【解决方案1】:

    您提供的是您的事件中心命名空间,而不是您要发布到该命名空间下的事件中心实例的名称。

    根据您创建命名空间的方式,您可能有也可能没有可供使用的事件中心。查看事件中心资源时,命名空间的事件中心名称列在 Azure 门户屏幕底部的网格中。 (在示例中,我的称为“dummy”)。如果您在该网格中没有看到任何项目,您可以使用顶部菜单栏中的+ Event Hub 按钮创建一个。

    一旦您知道要发布到的事件中心的名称,您就可以在代码的这一行中设置它:

    private const string eventHubName = "emailsevents.servicebus.windows.net";

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      相关资源
      最近更新 更多