I am an azure novice. My setup is as follows. I've got an IoT Hub, An Event Hub, an Azure function. The idea is to send messages to the IoT hub, route them to the Event Hub based on a certain message type, handle these events with the use of the function.
I created a sample console app to send messages from my machine to the IoT hub. Created an azure function on Visual Studio (.Net Core) and published it to an azure function app.
Now, when I run the console app project and the function app projects together , I see the messages being received on the IoT hub (by looking at the azure portal), and the function getting triggered and receiving the message that I sent (by looking at the console that pops up on my machine, with the function app).
My issue is, when I then check the azure portal, I see the function execution count as 0, even though I can see the function is picking the events when I check locally. Any idea why this might be the case?
Event received by the function
zero executions shown on azure portal
The function code is based on the template that comes with Visual Studio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace FunctionApp2
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task Run([EventHubTrigger("azureiotquickstarteventhub", Connection = "AzureEventHubConnectionString")] EventData[] events, ILogger log)
{
var exceptions = new List<Exception>();
foreach (EventData eventData in events)
{
try
{
string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
// Replace these two lines with your processing logic.
log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
await Task.Yield();
}
catch (Exception e)
{
// We need to keep processing the rest of the batch - capture this exception and continue.
// Also, consider capturing details of the message that failed processing so it can be processed again later.
exceptions.Add(e);
}
}
// Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.
if (exceptions.Count > 1)
throw new AggregateException(exceptions);
if (exceptions.Count == 1)
throw exceptions.Single();
}
}
}