3
votes

I'm trying to debug an Azure Function locally. It's an EventHubTrigger.

The problem is that I need to debug the code locally because I still don't have the "real" settings.

My code currently looks like this:

public static class Notificator
{
    [FunctionName("Notificator")]
    public static async Task Run([EventHubTrigger("achievements")]UserAchivementNofication notification, ILogger log)
    {
    }
}

But when I try to debug it, I'm getting this error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Notificator.Run'. Microsoft.Azure.WebJobs.ServiceBus: No event hub receiver named achievements.

And it's normal, because it doesn't exist.

My local.settings.json is like this:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
    }
}

How can I debug my code?

Thank you!

1
Create a test Event Hub and send some sample events there? - Mikhail Shilkov
How do I create a test EventHub? I'm using Azure Storage Explorer and I only see Queues, Tables and Blobs :( - SuperJMN
Event Hubs are not part of Storage. Just make a new one via portal. "Test" is more about intended usage, otherwise it's just a normal Event Hub, - Mikhail Shilkov
I cannot create it in the Azure Portal because I don't have access to the final Event Hub yet and I don't own any subscription myself :( - SuperJMN
You could refer to this article about Testing Azure Function with Event Hub Trigger Locally. - Joey Cai

1 Answers

3
votes

You need to create an EventHub on Azure so that you can test the EventHug trigger locally,

  1. Goto local.settings.json to add some settings:
{
  "IsEncrypted": false,
  "Values": {
     "AzureWebJobsStorage": "UseDevelopmentStorage=true",
     "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
     "EventHubConnectionString": "YourEventHubConnectionString"
  }
}
  1. Your function should be like this:

    public static void Run([EventHubTrigger("EventHubName", Connection = "EventHubConnectionString")]EventData myEventHubMessage, TraceWriter log)