如何在本地调试EventHubTrigger? [英] How to debug EventHubTrigger locally?
问题描述
我正在尝试在本地调试Azure功能.这是一个EventHubTrigger.
I'm trying to debug an Azure Function locally. It's an EventHubTrigger.
问题是我需要在本地调试代码,因为我仍然没有真实"设置.
我的代码当前如下所示:
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:错误索引方法'Notificator.Run'.Microsoft.Azure.WebJobs.ServiceBus:无事件中心接收者命名为成就.
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.
我的local.settings.json是这样的:
My local.settings.json is like this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true"
}
}
如何调试我的代码?
谢谢!
推荐答案
您需要在Azure上创建一个EventHub,以便可以在本地测试EventHug触发器,
You need to create an EventHub on Azure so that you can test the EventHug trigger locally,
- 转到local.settings.json以添加一些设置:
{
"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)
这篇关于如何在本地调试EventHubTrigger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!