[英]Cosmos db change feed trigger not firing after function goes to sleep
[英]Azure Cosmos DB Change feed function not firing
我正在編寫一些代碼,使用 Cosmos 作為我的存儲來實現事件溯源。 我的初始文檔已成功寫入集合。 然后,我設置了一個 Azure 函數,該函數在更改該集合的提要時觸發並將該項目復制到另一個集合。
我的問題是,雖然這一切正常,如果我在本地調試函數應用程序(更改通過並且沒有問題處理),該函數一旦作為函數應用程序發布就不會觸發。 該函數存在但總執行計數始終為 0。這就像該函數沒有在計時器上運行並檢查提要。 我的函數應用程序中的其他函數按預期工作。
我的功能代碼是
[FunctionName("EventSourceWrite")]
public static void Run([CosmosDBTrigger(
databaseName: "Puffin",
collectionName: "EventSource",
ConnectionStringSetting = "EventSourceConnection",
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
{
if (input != null && input.Count > 0)
{
log.LogInformation("Documents modified " + input.Count);
log.LogInformation("First document Id " + input[0].Id);
var container = Cosmos.GetItemsContainer();
foreach (var doc in input)
{
var item = JsonConvert.DeserializeObject<Item>(doc.ToString());
// reset the Id
item.Id = item.ItemId;
if(!string.IsNullOrEmpty(item.CollectionId))
{
container.UpsertItemAsync(item, new Microsoft.Azure.Cosmos.PartitionKey(item.CollectionId));
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.