How to debug EventHubTrigger locally?

喜夏-厌秋 提交于 2021-01-28 04:06:06

问题


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:


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)
    


来源:https://stackoverflow.com/questions/52145719/how-to-debug-eventhubtrigger-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!