【问题标题】:Azure Function for Cosmos DB change feed feed won't run: No job functions foundCosmos DB 更改源源的 Azure 函数不会运行:找不到作业函数
【发布时间】:2021-09-22 21:54:05
【问题描述】:

我正在编写一个订阅 Cosmos DB 更改源的 Azure Function 应用。当我使用 Visual Studio 2019 在本地运行应用程序 (F5) 时,我在 CLI 上收到以下错误:

Azure Function Core Tools reports "No job functions found."

整个代码sn-p如下:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;

namespace ZZZ.ChangeFeedSubscriber
{
    public static class ChangeFeedSubscriber
    {
        [FunctionName("ChangeFeedSubscriber")]
        public static void Run([CosmosDBTrigger(
            databaseName: "XXX",
            collectionName: "YYY",
            ConnectionStringSetting = "XXX",
            LeaseCollectionName = "leases")] IReadOnlyList<Doc> docs, FunctionContext context)
        {
            var logger = context.GetLogger("ChangeFeedSubscriber");

            if (docs != null && docs.Count > 0)
            {
                logger.LogInformation("Documents modified: " + docs.Count);

                foreach (var doc in docs)
                {
                    logger.LogInformation("ID: " + doc.id);
                }
            }
        }
    }
}

我尝试在应用程序参数上设置“--verbose”以查看日志输出,但它引发了错误。

Adding "--verbose" throws an error.

Result of adding "--verbose" to application arguments.

我也尝试设置“start --verbose”,但也报错了。

Adding "start --verbose" also throws an error.

Result of adding "start --verbose" to application arguments.

我不知道此时我还能检查什么。应用程序无法启动,并且根据我所做的搜索,我看不到日志输出。

任何帮助将不胜感激。蒂亚!

【问题讨论】:

    标签: azure azure-functions azure-cosmosdb-changefeed


    【解决方案1】:

    看起来您在这里混合了 in-proc 和 out-of-process 模型,这导致了问题。

    从代码中,我假设您有一个进程外(隔离工作者)函数应用程序。但是你的第二行是一个 using 语句来导入 Microsoft.Azure.WebJobs 命名空间。我还看到您正在使用来自 Microsoft.Azure.WebJobs 包的 FunctionName 属性。

    对于进程外功能应用,您不应使用 webjobs 包。相反,您应该使用来自Microsoft.Azure.Functions.Worker.Extensions的等效包

    要解决此问题,请打开您的 .csproj 文件并删除 Microsoft.Azure.WebJobs.Extensions.CosmosDB 包。为Microsoft.Azure.Functions.Worker.Extensions.CosmosDB(进程外工作人员版本)添加一个新条目。您也可以使用 nuget 包管理器 UI 执行相同操作。

    更改后,您的 csproj 文件将如下所示

    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="3.0.9" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" OutputItemType="Analyzer" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.1.0" />
    </ItemGroup>
    

    还要确保您现在使用的是Function 属性而不是FunctionName,并删除了用于导入Microsoft.Azure.WebJobs 命名空间的 using 语句。

    [Function("Function1")]                
    public static void Run([CosmosDBTrigger(
    

    通过此更改,您的函数将被发现。

    【讨论】:

    • 感谢您的意见!我的 Azure Function 应用现在可以正常启动。更具体地说,用于 Cosmos DB 触发器的 Visual Studio 2019 模板随附安装了 Microsoft.Azure.Functions.Worker,但未安装 Microsoft.Azure.Functions.Worker.Extensions.CosmosDB。根据您的指南删除 Microsoft.Azure.WebJobs,然后将 Microsoft.Azure.Functions.Worker.Extensions.CosmosDB 添加到项目中,即可解决此问题。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    相关资源
    最近更新 更多