我创建了一个新的 Azure 函数,希望它由 EventGrid 运行。我使用 Visual Studio 2022 社区。p>
我想通过 Postman 调试该函数,但找不到方法。
我的 TestFunction.cs:
public static class TestFunction
{
[FunctionName("Function1")]
public static async Task Function1([EventGridTrigger] EventGridEvent triggerEvent,
[EventGrid(TopicEndpointUri = "Topic", TopicKeySetting = "TopicKey")] IAsyncCollector<EventGridEvent> outputEvents,
ILogger log)
{
//TODO
}
}
当我 F5 要调试的项目时,控制台应用程序显示:
Functions:
Function1: eventGridTrigger
For detailed output, run func with --verbose flag.
我尝试通过 postman 发布到以下网址:
http://localhost:7071/runtime/webhooks/EventGrid?functionName=Function1
发生了两件事:
1.Postman请求返回:
cannot find function: 'Function1'
2.控制台应用程序显示:
[2022-03-14T12:20:57.715Z] Executing HTTP request: {
[2022-03-14T12:20:57.717Z] requestId: "a31453db-3717-43d8-a008-bd459a454fb0",
[2022-03-14T12:20:57.718Z] method: "POST",
[2022-03-14T12:20:57.718Z] userAgent: "PostmanRuntime/7.29.0",
[2022-03-14T12:20:57.719Z] uri: "/runtime/webhooks/EventGrid"
[2022-03-14T12:20:57.721Z] }
[2022-03-14T12:20:57.724Z] cannot find function: 'Function1', available function names: []
[2022-03-14T12:20:57.725Z] Executed HTTP request: {
[2022-03-14T12:20:57.726Z] requestId: "a31453db-3717-43d8-a008-bd459a454fb0",
[2022-03-14T12:20:57.727Z] identities: "(WebJobsAuthLevel:Admin, WebJobsAuthLevel:Admin)",
[2022-03-14T12:20:57.728Z] status: "404",
[2022-03-14T12:20:57.729Z] duration: "10"
[2022-03-14T12:20:57.729Z] }
这是我阅读的用于获取调试 Url 的帖子:https://harrybellamy.com/posts/debugging-azure-function-event-grid-triggers-locally/
为了调试 Postman 的函数,我是否缺少任何东西?
提前谢谢您!
<小时/>更新2022年3月15日
当我删除这一行(Function1 中的参数)后它就可以工作,我可以调试 Function1:
[EventGrid(TopicEndpointUri = "MyEventGridTopicUriSetting", TopicKeySetting = "MyEventGridTopicKeySetting")]IAsyncCollector<EventGridEvent> outputEvents,
最佳答案
引用的文章说:
If you try to send the request to the URL now, you will find that it doesn’t work. This is because Event Grid requests require a ‘magic’ header for them to work.
Add the following header to your request in your request generator:
aeg-event-type: Notification
关于c# - 如何在本地调试由EventGrid触发的Azure Function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71467670/