邮件未发送到Azure事件中心

时间:2018-10-23 17:14:12

标签: c# azure azure-eventhub

我正在学习Azure Events Hub。我已经从此链接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,   时间戳:10/23/2018 5:11:18 PM。

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

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

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.");
    }
}

}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我的EventHubName =“ myeventhubname”错误。我传递了事件中心名称空间值-用红色四舍五入。它给出了错误。 我将其更改为事件中心页面左列下的值->单击实体->事件中心 我使用了表格中以绿色四舍五入的名称。 enter image description here

相关问题