C# 消息未发送到Azure事件中心:放置令牌失败。状态代码:404,状态描述:消息实体。。。找不到
我正在学习Azure事件中心。我从这个链接下载了一个简单的应用程序。但当我尝试发送消息时,它会给我以下错误: 2018年10月23日晚上11:11:13>异常:放置令牌失败。状态代码: 404,状态描述:消息实体 “sb://demo.servicebus.windows.net/myTeam”无法 找到了。TrackingId:[我的跟踪ID], SystemTracker:iot bd madness.servicebus.windows.net:iot bd madness, 时间戳:2018年10月23日下午5:11:18C# 消息未发送到Azure事件中心:放置令牌失败。状态代码:404,状态描述:消息实体。。。找不到,c#,azure,azure-eventhub,C#,Azure,Azure Eventhub,我正在学习Azure事件中心。我从这个链接下载了一个简单的应用程序。但当我尝试发送消息时,它会给我以下错误: 2018年10月23日晚上11:11:13>异常:放置令牌失败。状态代码: 404,状态描述:消息实体 “sb://demo.servicebus.windows.net/myTeam”无法 找到了。TrackingId:[我的跟踪ID], SystemTracker:iot bd madness.servicebus.windows.net:iot bd madness, 时间戳:20
在Azure Event Hub仪表板中,所有传入请求(从控制台应用程序发送)都可以通过图表看到。但这些都是我在控制台应用程序中尝试时实际失败的请求 N.B:给定的连接字符串不是真实的
public class Program
{
private static EventHubClient eventHubClient;
private const string EventHubConnectionString = "Endpoint=sb://iot-bd-madness.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
private const string EventHubName = "Iot-Bd-Madness";
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
private static async Task MainAsync(string[] args)
{
// Creates an EventHubsConnectionStringBuilder object from a the connection string, and sets the EntityPath.
// Typically the connection string should have the Entity Path in it, but for the sake of this simple scenario
// we are using the connection string from the namespace.
var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
{
EntityPath = EventHubName
};
eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
await SendMessagesToEventHub(100);
await eventHubClient.CloseAsync();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
// Creates an Event Hub client and sends 100 messages to the event hub.
private static async Task SendMessagesToEventHub(int numMessagesToSend)
{
for (var i = 0; i < numMessagesToSend; i++)
{
try
{
var message = $"Message {i}";
Console.WriteLine($"Sending message: {message}");
await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));
}
catch (Exception exception)
{
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
}
await Task.Delay(10);
}
Console.WriteLine($"{numMessagesToSend} messages sent.");
}
}
公共类程序
{
私有静态EventHubClient EventHubClient;
private const string EventHubConnectionString=“Endpoint=sb://iot bd madness.servicebus.windows.net/;sharedaccesskyname=RootManageSharedAccessKey;SharedAccessKey=aaaaaaaaaaaaaaaaaaaaaaaa=”;
private const string EventHubName=“Iot Bd Madness”;
公共静态void Main(字符串[]args)
{
MainAsync(args).GetAwaiter().GetResult();
}
专用静态异步任务mainsync(字符串[]args)
{
//从连接字符串中创建EventHubsConnectionStringBuilder对象,并设置EntityPath。
//通常,连接字符串中应该包含实体路径,但出于这个简单场景的考虑
//我们正在使用名称空间中的连接字符串。
var connectionStringBuilder=新的EventHubsConnectionStringBuilder(EventHubConnectionString)
{
EntityPath=EventHubName
};
eventHubClient=eventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
等待SendMessagesToEventHub(100);
等待eventHubClient.CloseAsync();
控制台。WriteLine(“按任意键退出”);
Console.ReadLine();
}
//创建事件中心客户端并向事件中心发送100条消息。
专用静态异步任务SendMessagesToEventHub(int numMessagesToSend)
{
对于(变量i=0;i异常:{Exception.Message}”);
}
等待任务。延迟(10);
}
WriteLine($“{numMessagesSend}已发送消息”);
}
}
}我遇到了同样的问题。我的EventHubName=“MyEventThubName”是错误的。我传递了事件中心名称空间值-四舍五入为红色。它给出了一个错误。 我在Event Hub页面左栏->单击实体->Event Hub下将其更改为值 我使用了表格中以绿色四舍五入显示的名称。
在Azure Event Hub仪表板中,所有传入请求(从控制台应用程序发送)都可以通过图表看到。但这些都是我在控制台应用程序中尝试时实际失败的请求。请检查我的代码。@davidmakogan我已使用正确的连接字符串(安全密钥除外)再次编辑了我的问题。我遇到了完全相同的问题,请确保已创建事件中心命名空间和事件中心!