0
votes

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