每个绑定都有一个用于本地测试和调试的 HTTP 端点。
- https://localhost:7071/admin/functions/{FUNCNAME}
这至少适用于 QueueTrigger、ServiceBusTrigger、TimerTrigger、EventHubTrigger。
发送带有 JSON 格式的预期数据的 POST 请求。
{ "input": "YOUR JSON SERIALIZED AND ESCAPED DATA" }
对于需要数据的触发器,将数据作为序列化字符串放入“输入”中。看事件中心触发器下面进一步举例。
定时器触发
对于 TimerTrigger 使用:
{ "input": null }
事件网格触发器
要在某些触发器上执行此操作有点棘手。这是为了事件网格触发器:
- https://localhost:7071/runtime/webhooks/EventGrid/functionName={FUNCNAME}
发送POST请求来执行。看here https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid-trigger?tabs=csharp%2Cbash了解详情。该对象必须是一个数组。
事件中心触发器
The 事件中心触发器像其他触发器一样接收数据作为单个 JSON 对象。结构如下EventData
类,但唯一必需的字段是“SystemProperties”。似乎没有序列化器特定的设置,属性名称不改变大小写等。
将其作为正文发布;
{
"input": "{\"SystemProperties\":{},\"SomeId\":\"123\",\"Status\":\"Available\"}"
}
事件中心的主体是“输入”的转义和序列化值。
请注意,这同样适用于 IoT 中心
元数据
对于所有触发器,您可以通过 GET 请求获取元数据。为事件中心触发器这可能看起来像这样:
{
"name": "StateChange",
"script_root_path_href": "http://localhost:7071/admin/vfs/StateChange/",
"script_href": "http://localhost:7071/admin/vfs/bin/MyApp.Notifications.Functions.dll",
"config_href": "http://localhost:7071/admin/vfs/StateChange/function.json",
"test_data_href": null,
"href": "http://localhost:7071/admin/functions/StateChange",
"invoke_url_template": null,
"language": "DotNetAssembly",
"config": {
"generatedBy": "Microsoft.NET.Sdk.Functions-3.0.11",
"configurationSource": "attributes",
"bindings": [
{
"type": "eventHubTrigger",
"consumerGroup": "regular",
"connection": "EventHub_Hub_Status",
"eventHubName": "%EventHub_Status%",
"name": "statusUpdateMessage"
}
],
"disabled": false,
"scriptFile": "../bin/MyApp.Notifications.Functions.dll",
"entryPoint": "MyApp.Notifications.Functions.StateChange.Run"
},
"files": null,
"test_data": null,
"isDisabled": false,
"isDirect": true,
"isProxy": false
}
当然,您可以使用所有路径来检索数据,包括二进制文件。编写复杂的集成测试非常方便。