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:
You can use that name instead of
IoTHubTrigger("messages/events"