MessagingEntityNotFoundException:找不到消息实体“ihsuprodsgres029dednamespace:eventhub:”

问题描述 投票:0回答:2

我只是尝试使用 Azure IOT Hub 将我的设备连接到云。但我收到如下错误。

MessagingEntityNotFoundException:找不到消息实体“ihsuprodsgres029dednamespace:eventhub:iothub-ehub-”。 TrackingId:4772b610-8ff3-4709-8ea9-ffcd5784fe1c_B4,SystemTracker:ihsuprodsgres029dednamespace:eventhub:iothub-ehub-sibeeshiot-176205-a588b66686~16383|team01,时间戳:2017年6月23日3:07:54 PM TrackingId:41110b704d814af497fd9924da6714d8_G4,SystemTracker :gateway2,时间戳:6/23/2017 3:07:55 PM,参考 ID:41110b704d814af497fd9924da6714d8_G4

如果您遇到过同样的问题,可以帮我解决一下吗?下面是我正在尝试的代码。

static void Main(string[] args) {
    Console.WriteLine("Receive messages. Ctrl-C to exit.\n");
    eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, iotHubD2cEndpoint);

    var d2cPartitions = eventHubClient.GetRuntimeInformation().PartitionIds;

    CancellationTokenSource cts = new CancellationTokenSource();

    System.Console.CancelKeyPress += (s, e) = >{
        e.Cancel = true;
        cts.Cancel();
        Console.WriteLine("Exiting...");
    };

    var tasks = new List < Task > ();
    foreach(string partition in d2cPartitions) {
        tasks.Add(ReceiveMessagesFromDeviceAsync(partition, cts.Token));
    }
    Task.WaitAll(tasks.ToArray());
}
private static async Task ReceiveMessagesFromDeviceAsync(string partition, CancellationToken ct) {
    var eventHubReceiver = eventHubClient.GetConsumerGroup("Team01").CreateReceiver(partition, DateTime.UtcNow);
    while (true) {
        if (ct.IsCancellationRequested) break;
        EventData eventData = await eventHubReceiver.ReceiveAsync();
        if (eventData == null) continue;

        string data = Encoding.UTF8.GetString(eventData.GetBytes());
        Console.WriteLine("Message received. Partition: {0} Data: '{1}'", partition, data);
    }
}
c# azure azure-web-app-service azure-iot-hub azure-iot-sdk
2个回答
4
投票

您的 iotHubD2cEndpoint 值似乎不是正确的事件中心兼容名称(可能您正在使用 消息/事件,例如 Azure IoT 中心端点)。

以下屏幕片段显示了与事件中心兼容的事件端点:

  • 另一个选项是使用 Azure IoT 中心连接字符串和端点事件,请参阅以下示例:

    iotHubD2cEndpoint =“消息/事件” connectionString =“主机名=*****.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=******”


0
投票

对于其他到达这里的人...我通过以下方式找到了

Event Hub compatible endpoint

  • Azure 门户 (https://portal.azure.com)
  • 打开您的 IotHub 配置
  • 在左侧菜单...
  • 集线器设置,内置端点
  • 下方事件中心兼容端点...
  • Event Hub compatible endpoint
    .
© www.soinside.com 2019 - 2024. All rights reserved.