3

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
  • 1
    Create a test Event Hub and send some sample events there? – Mikhail Shilkov Sep 03 '18 at 08:31
  • How do I create a test EventHub? I'm using Azure Storage Explorer and I only see Queues, Tables and Blobs :( – SuperJMN Sep 03 '18 at 08:45
  • 1
    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 Sep 03 '18 at 09:07
  • 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 Sep 03 '18 at 09:10
  • You could refer to this [article](https://nascent.blog/2017/05/22/azure-functions-event-hub-local/) about Testing Azure Function with Event Hub Trigger Locally. – Joey Cai Sep 03 '18 at 09:11
  • Event Hub is not the best service to test locally - without access to any kind of test service, you will struggle to test your solution. If you do not have access to a subscription, you can create one for free. – kamil-mrzyglod Sep 03 '18 at 20:02
  • See [this](https://stackoverflow.com/a/68122651/294657) answer for a fully local approach. – kaqqao May 31 '22 at 21:56

1 Answers1

3

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)
    
SLdragon
  • 1,477
  • 16
  • 19