找不到事件中心资源

问题描述

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门户屏幕底部的网格中列出了名称空间的事件中心的名称。 (在本示例中,我的被称为“虚拟”)。如果在该网格中没有看到任何项目,则可以使用顶部菜单栏中的+ Event Hub按钮来创建一个项目。

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

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

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...