繁体   English   中英

IoT Hub to Azure Function - The listener for function was unable to start Azure.Messaging.EventHubs could not be found

[英]IoT Hub to Azure Function - The listener for function was unable to start Azure.Messaging.EventHubs could not be found

按照将Azure Function 链接到 IoT 中心消息接收的指南,我收到错误消息:

[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

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

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

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

您可以在从以下位置获取端点的同一位置找到正确的事件中心名称: Azure 门户的屏幕截图,显示事件中心名称

您可以使用该名称而不是

IoTHubTrigger("messages/events"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM