azure - 未找到事件中心资源

标签 azure azure-eventhub

https://learn.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.");
            }
        }
    }
}

我收到一个未处理的异常。 EventHubsException(ResourceNotFound) 当我到达终点线时

        using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();

最佳答案

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

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

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

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

enter image description here

关于azure - 未找到事件中心资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616924/

相关文章:

Azure数据工厂: Access web service residing in virtual network

azure - 通过 Azure 数据工厂从 ftp 站点获取 zip 和非压缩文件 - 解压缩

azure - 是否可以使用 Terraform 在 Azure 上创建专用图像?如何?

java - 注册EventProcessorHost时失败

c# - Azure App Functions 应用程序 'appname' 已关闭

azure - 无法从本地网络远程登录到 Azure VM

azure - Terraform Azure 数据工厂创建

c# - 有没有办法在 Azure eventhub 中查找特定事件

c# - 从 Asp.Net 站点将数据发送到 EventHub

c# - .net core Web应用程序并从azure事件中心读取数据