如何解决找不到事件中心资源
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";
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。