【问题标题】:How in azure function bind event hub output parameter via attributes天蓝色函数中如何通过属性绑定事件中心输出参数
【发布时间】:2018-04-18 14:43:59
【问题描述】:

我想使用属性将输入和输出参数从事件中心绑定到事件中心。

在文档中只有如何使用return 语句绑定到输出的信息 https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs#output---c-example

[FunctionName("EventHubOutput")] [return: EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")] public static string Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log) { log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); return $"{DateTime.Now}"; }

但我想使用ICollector<EventData> outputEventHub 作为参数来获得如下内容

[FunctionName("EventHubRewriter")]
public static void Run([EventHubTrigger("samples-workitems", Connection ="EventHubInputConnectionAppSetting")] EventData[] inputMessages, ICollector<EventData> outputMessages, TraceWriter log)
{
    ...
}

如何使用输出事件中心的属性生成绑定?

更新: 以下是如何为属性绑定生成 function.json 的信息:function.json generation

【问题讨论】:

    标签: azure-functions azure-eventhub


    【解决方案1】:

    几乎一模一样:

    [EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")] 
    ICollector<EventData> outputMessages
    

    完整签名:

    [FunctionName("EventHubRewriter")]
    public static void Run(
        [EventHubTrigger("samples-workitems", Connection ="EventHubInputConnectionAppSetting")] 
        EventData[] inputMessages, 
        [EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")]
        ICollector<EventData> outputMessages, 
        TraceWriter log)
    {
        ...
    }    
    

    【讨论】:

    • 我以为是这样的。但是在部署之后它会生成如下的function.json:`{“generatedBy”:“Microsoft.NET.Sdk.Functions.Generator-1.0.6”,“configurationSource”:“attributes”,“bindings”:[{“type ": "eventHubTrigger", "connection": "EventHubInputConnectionAppSetting", "path": "output", "name": "eventDataSet" } ], "disabled": false, "scriptFile": "../bin/EventHub. dll", "entryPoint": "EventHub.Ordered.Run" } `
    • @wolszakp 没关系。输入/输出绑定不包含在自动生成的function.json
    • 好的,谢谢你的解释。但是使用此属性的原因是什么 - 我认为由于此属性function.json 将自动生成。
    • @wolszakp Runtime 将直接使用该属性,跳过function.json sectuon
    • 我的意思是文档中的内容:好的,谢谢您的解释。但是使用此属性的原因是什么 - 我认为由于此属性function.json 将自动生成。我指的是文档中的内容:docs.microsoft.com/en-us/azure/azure-functions/…
    猜你喜欢
    • 2019-03-24
    • 2019-12-14
    • 1970-01-01
    • 2019-11-27
    • 2017-11-26
    • 1970-01-01
    • 2015-01-21
    • 2019-09-28
    • 1970-01-01
    相关资源
    最近更新 更多