【问题标题】:IoT Hub to Azure Function - The listener for function was unable to start Azure.Messaging.EventHubs could not be foundIoT 中心到 Azure 函数 - 函数的侦听器无法启动 Azure.Messaging.EventHubs 找不到
【发布时间】:2022-07-29 15:00:01
【问题描述】:

按照指南链接an Azure Function to IoT Hub message receipt,我收到错误:

[2022-07-28T23:11:20.651Z] The listener for function 'DataFromDevice' was unable to start.
System.Private.CoreLib: One or more errors occurred. (The messaging entity
'sb://iothub-ns-mynamespace.servicebus.windows.net/messages/events' could not be found. 
To know more visit https://aka.ms/sbResourceMgrExceptions.  (messages/events)).

我按照指南从IoT Hub -> Built-in endpoints -> Event Hub compatible endpoint 中提取了连接字符串,但是我不得不在最后删除EntityPath

否则我的代码编译和上传正常(上面提到了运行时错误),代码如下:

using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;
using Microsoft.Azure.WebJobs;
using Azure.Messaging.EventHubs;
using System.Text;
using System.Net.Http;
using Microsoft.Extensions.Logging;

public class DataFromDevice
{
    private static HttpClient client = new HttpClient();
    
    [FunctionName("DataFromDevice")]
    public void Run([IoTHubTrigger("messages/events", Connection = "IoTHubConnectionString")]EventData message, ILogger log)
    {
        log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Span)}");
    }
}

【问题讨论】:

    标签: azure azure-functions azure-iot-hub


    【解决方案1】:

    messages/events 是 IoT 中心用于路由消息的内部名称。但是,如果您想从该流中读取数据,则必须使用不同的名称。

    您可以在获得端点的同一位置找到正确的事件中心名称:

    您可以使用该名称代替

    IoTHubTrigger("messages/events"
    

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 2023-02-03
      • 2021-11-30
      • 2021-09-30
      • 2018-06-28
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多