问题
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,
- Goto local.settings.json to add some settings:
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "AzureWebJobsDashboard": "UseDevelopmentStorage=true", "EventHubConnectionString": "YourEventHubConnectionString" } }
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