2017-06-23 12 views
2

我只是試圖使用Azure IOT Hub將我的設備連接到雲。但是我收到如下錯誤。MessagingEntityNotFoundException:無法找到消息傳遞實體'ihsuprodsgres029dednamespace:eventhub:'

MessagingEntityNotFoundException:無法找到消息傳遞實體'ihsuprodsgres029dednamespace:eventhub:iothub-ehub-'。 TrackingId:4772b610-8ff3-4709-8ea9-ffcd5784fe1c_B4,SystemTracker:ihsuprodsgres029dednamespace:eventhub:iothub-ehub-sibeeshiot-176205-a588b66686〜16383 | team01,時間戳:6/23/2017 3:07:54 PM TrackingId:41110b704d814af497fd9924da6714d8_G4,SystemTracker :網關2,時間戳:2017年6月23日下午3時07分55秒,referenceId: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); 
      } 
     } 

回答

4

它看起來像你的iotHubD2cEndpoint值是不正確的事件樞紐兼容的名稱(可能是您正在使用的消息/事件如天青物聯網中心端點)。

下面的屏幕片段顯示了事件的事件樞紐兼容端點:

EventHubEndpoint

  • 另一種選擇是使用Azure的物聯網集線器連接字符串和終點事件,請看下面的例子:

    iotHubD2cEndpoint = 「消息/事件」 的connectionString = 「主機名= ***** azure-devices.net; SharedAccessKeyName = iothubowner; SharedAccessKey = ******」