簡體   English   中英

Cosmos DB - 更改 Feed 觸發器:“my-function-name”的偵聽器無法啟動

[英]Cosmos DB - Change Feed Trigger: The Listener for 'my-function-name' was unable to start

運行 azure function 應用程序時出現以下錯誤:

[7/15/2020 8:26:08 AM] function 'NotificationChangeFeed' 的偵聽器無法啟動。 [7/15/2020 8:26:08 AM] function 'NotificationChangeFeed' 的偵聽器無法啟動。 Microsoft.Azure.DocumentDB.Core:Object 引用未設置為 object 的實例。

錯誤截圖: 在此處輸入圖像描述

這是我的更改饋送觸發器 Azure Function:

public static class NotificationChangeFeed
    {
        [FunctionName("NotificationChangeFeed")]
        public static async Task Run([CosmosDBTrigger(
            databaseName: "FleetHubNotifications",
            collectionName: "Notification",
            ConnectionStringSetting = "CosmosDBConnection",
            LeaseCollectionName = "leases", CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> input, 
            [Inject] ILoggingService loggingService,
            [Inject] IEmailProcessor emailProcessor)
        {
            var logger = new Logger(loggingService);

            try
            {
                if (input != null && input.Count > 0)
                {
                    foreach (Document document in input)
                    {
                        string requestBody = document.ToString();
                        var notification = requestBody.AsPoco<Notification>();
                        
                        var result = await emailProcessor.HandleEmailAsync(notification, logger);

                        if (result)
                        {
                            logger.Info($"Email Notification sent successfully for file name: {document.Id}");
                        }
                        else
                        {
                            logger.Warning($"Unable to process document for Email Notification for file with name: {document.Id}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Unable to process Documents for Email Notification for Files: {input.Count}", ex,
                    nameof(NotificationChangeFeed));
            }
        }
    }

local.settings.json:

{
  "IsEncrypted": "false",
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "CosmosDbId": "FleetHubNotifications",
    //Localhost
    "CosmoDbAuthKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
    "CosmoDbEndpoint": "https://localhost:8081/",
    "CosmosDBConnection": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
}
}

本地存儲模擬器的連接字符串正確。

如果您的防火牆限制 func 訪問存儲帳戶,則可能會報告此錯誤。 防火牆是監聽器無法訪問虛擬存儲模擬器的原因之一。

在本地運行 function 時,除 httptrigger 之外的所有觸發器都需要使用 Storage Emulator。 如果防火牆限制偵聽器對虛擬存儲的訪問,則在執行功能時可能會出現問題。

嘗試禁用防火牆,看看是否能解決問題。

當然,也有可能是 Storage Emulator 服務沒有打開。 嘗試輸入

"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" status

在 cmd 中檢查狀態。

如果返回 false,請輸入以下命令以啟動 Storage Emulator:

"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init
"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start

總結一下:

這個監聽器不能啟動一般是有3個原因。

1.連接字符串錯誤阻止連接,

2.防火牆設置

3.部分服務未開啟。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM