Azure Function App Cosmos DB trigger connection drop

ぃ、小莉子 提交于 2021-02-11 12:29:23

问题


I am using a Function app with cosmos DB trigger, when running locally, the behavior is very strange as I stop receiving events randomly, like if the connection to the Lease collection drops. I am getting an error message that says a read operation fails to Blob storage, but not sure if this is related. Here's the error:

There was an error performing a read operation on the Blob Storage Secret Repository. 
Please ensure the 'AzureWebJobsStorage' connection string is valid

I am running the function app with this code: func host start --cors * --verbose

And here's the CosmosDBOptions object I can see in the console:

[2021-02-09T16:17:58.305Z] CosmosDBOptions
[2021-02-09T16:17:58.307Z] {
[2021-02-09T16:17:58.307Z]   "ConnectionMode": null,
[2021-02-09T16:17:58.308Z]   "Protocol": null,
[2021-02-09T16:17:58.309Z]   "LeaseOptions": {
[2021-02-09T16:17:58.310Z]     "CheckpointFrequency": {
[2021-02-09T16:17:58.310Z]       "ExplicitCheckpoint": false,
[2021-02-09T16:17:58.311Z]       "ProcessedDocumentCount": null,
[2021-02-09T16:17:58.311Z]       "TimeInterval": null
[2021-02-09T16:17:58.312Z]     },
[2021-02-09T16:17:58.313Z]     "FeedPollDelay": "00:00:05",
[2021-02-09T16:17:58.313Z]     "IsAutoCheckpointEnabled": true,
[2021-02-09T16:17:58.314Z]     "LeaseAcquireInterval": "00:00:13",
[2021-02-09T16:17:58.314Z]     "LeaseExpirationInterval": "00:01:00",
[2021-02-09T16:17:58.315Z]     "LeasePrefix": null,
[2021-02-09T16:17:58.316Z]     "LeaseRenewInterval": "00:00:17"
[2021-02-09T16:17:58.316Z]   }
[2021-02-09T16:17:58.323Z] }

and my host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

Finally, that issue started since I added a shared folder, not sure if it's related but it's really annoying, deleting leases collection solves temporary the problem but It costs a lot of time and all the other running functions break because I clean all the collection.


回答1:


There are two important points:

  1. If you have one Azure Function deployed on Azure and one running locally in your machine with the same lease configuration listening for changes in the same monitored collection then these will behave as multiple instances of the same deployment and changes will be delivered to one or the other and you might experience "event loss" on the one running in Azure. This is documented in https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-changefeed-functions#some-changes-are-missing-in-my-trigger. If you want to have 2 independent Functions listening for changes in the same monitored collection, sharing the same lease collection, you need to use the LeaseCollectionPrefix configuration https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-create-multiple-cosmos-db-triggers
  2. The error you are seeing locally is potentially related to either not having the Azure Storage emulator running or not configuring the AzureWebJobsStorage configuration locally to use it. Azure Functions runtime (regardless of the Cosmos DB Trigger) requires a storage account. You can use UseDevelopmentStorage=true for the local storage emulator.


来源:https://stackoverflow.com/questions/66123208/azure-function-app-cosmos-db-trigger-connection-drop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!