The*_*ong 3 azure azure-eventhub azure-functions
我只是想问是否可以纯粹在本地计算机上执行 Azure 函数(事件中心触发器)而不依赖于任何 Azure 事件中心资源?我一直在关注 Microsoft 在本地开发 Azure Functions 的流程(链接),但似乎我需要填写事件中心连接字符串和名称。
public static async Task Run([EventHubTrigger("samples-workitems", Connection = "eventhub-connectionstring")] EventData[] events, ILogger log)
有什么办法可以做到这一点吗?
Joe*_*use 10
每个绑定都有一个用于本地测试和调试的 HTTP 端点。
这至少适用于 QueueTrigger、ServiceBusTrigger、TimerTrigger、EventHubTrigger。
发送带有 JSON 格式的预期数据的 POST 请求。
{ "input": "YOUR JSON SERIALIZED AND ESCAPED DATA" }
Run Code Online (Sandbox Code Playgroud)
对于需要数据的触发器,将数据作为序列化字符串放入“输入”中。请参阅下面的EventHubTrigger示例。
对于 TimerTrigger 使用:
{ "input": null }
Run Code Online (Sandbox Code Playgroud)
要在某些触发器上执行此操作有点棘手。这是EventGridTrigger的:
发送POST请求来执行。详细信息请参见此处。该对象必须是一个数组。
EventHubTrigger像其他触发器一样接收数据作为单个 JSON 对象。结构遵循EventData类,但唯一必需的字段是“SystemProperties”。似乎没有序列化器特定的设置,属性名称不改变大小写等。
将其作为正文发布;
{
"input": "{\"SystemProperties\":{},\"SomeId\":\"123\",\"Status\":\"Available\"}"
}
Run Code Online (Sandbox Code Playgroud)
事件中心的主体是“输入”的转义和序列化值。
请注意,这同样适用于 IoT 中心
对于所有触发器,您可以通过 GET 请求获取元数据。对于EventHubTrigger,这可能如下所示:
{
"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
}
Run Code Online (Sandbox Code Playgroud)
当然,您可以使用所有路径来检索数据,包括二进制文件。编写复杂的集成测试非常方便。
| 归档时间: |
|
| 查看次数: |
5616 次 |
| 最近记录: |