简体   繁体   中英

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

Following guides to link an Azure Function to IoT Hub message receipt , I get the error:

[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)).

I pulled the connection string from the IoT Hub -> Built-in endpoints -> Event Hub compatible endpoint per the guides, I had to drop the EntityPath at the end however.

My code otherwise compiles and uploads OK (with runtime error mentioned above), and code is below:

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 is the internal name IoT Hub uses to route messages. However, if you want to read from that stream, you must use a different name.

You can find the correct Event Hub name in the same place you got the endpoint from: Azure 门户的屏幕截图,显示事件中心名称

You can use that name instead of

IoTHubTrigger("messages/events"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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