首页 > 解决方案 > 使用 Azure 函数 CLI 2x 创建 EvenHubTrigger

问题描述

我尝试将 Azure 函数 EventHubTrigger 1x 迁移到 2x。但是,我的 Azure 函数 CLI 2x 无法绑定我的触发器,我的输出是No job functions found. Try making your job classes and methods public..这是我的项目 在此处输入图像描述 我不知道我想念什么配置

谢谢你的帮助

标签: azure-functionseventtriggerazure-functions-core-tools

解决方案


首先,您的代码中没有绑定。首先,您错过了Function绑定以及没有Trigger绑定。下面是 EventHubTriggered Azure Function 的一个简单示例

public static class Function2
    {
        [FunctionName("Function2")]
        public static async Task Run([EventHubTrigger("samples-workitems", Connection = "ConnectionString")] EventData[] events, ILogger log)
        {
            var exceptions = new List<Exception>();

            foreach (EventData eventData in events)
            {
                string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);

                // Replace these two lines with your processing logic.
                log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
            }

        }
    }

推荐阅读