【发布时间】: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