消息未发送到 Azure 事件中心:放置令牌失败。状态代码:404,状态描述:消息实体... ...找不到

seb*_*ebu 3 c# azure azure-eventhub

我正在学习 Azure 事件中心。我从这个链接https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send下载了一个简单的应用程序。但是当我尝试发送消息时,它给了我这个错误:

10/23/2018 11:11:13 PM > 例外:放置令牌失败。状态代码:404,状态描述:无法找到消息实体“sb://demo.servicebus.windows.net/myTeam”。TrackingId:[我的跟踪 ID], SystemTracker:iot-bd-madness.servicebus.windows.net:IoT-BD-Madness, Timestamp:10/23/2018 5:11:18 PM。

在 Azure 事件中心仪表板中,所有传入请求(从控制台应用程序发送)都可以通过图表看到。但是当我在控制台应用程序中尝试时,这些请求实际上都失败了

注意:给定的连接字符串不是真实的

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.");
    }
}
Run Code Online (Sandbox Code Playgroud)

}

小智 11

我遇到了同样的问题。我的 EventHubName = "myeventhubname" 是错误的。我传递了事件中心命名空间值 - 以红色四舍五入。它给出了错误。我将其更改为 Event Hub 页面左列下的 value -> 单击 Entities -> Event Hubs 我使用了表中显示的名称,该名称以绿色四舍五入。 在此处输入图片说明