無伺服器事件型架構搭配 Azure Cosmos DB 和 Azure Functions

適用於:NoSQL

Azure Functions 能以最簡單的方式連線至變更摘要。 您可以建立小型反應式 Azure Functions,以在 Azure Cosmos DB 容器變更摘要的每個新事件上自動觸發。

Serverless event-based Functions working with the Azure Functions trigger for Azure Cosmos DB

透過適用於 Azure Cosmos DB 的 Azure Functions 觸發程序,您可以利用變更摘要處理器可縮放且可靠的事件偵測功能,而不需要維護任何背景工作角色基礎結構。 只需要專注於 Azure Functions 的邏輯,不必擔心事件來源管線的其餘部分。 您甚至可以混用觸發程序與任何其他 Azure Functions 繫結

注意

Azure Functions 觸發程序使用最新版本變更摘要模式。目前,適用於 Azure Cosmos DB 的 Azure Functions 觸發程序僅支援搭配 API for NoSQL 一起使用。

需求

若要實作無伺服器事件型流程,您需要:

  • 受監視的容器:受監視的容器是指受監視的 Azure Cosmos DB 容器,其會儲存用來產生變更摘要的資料。 在受監視的容器中,任何插入和更新都反映在容器的變更摘要中。
  • 租用容器:租用容器跨多個動態無伺服器 Azure Function 執行個體維護狀態,並啟用動態縮放。 您可以使用適用於 Azure Cosmos DB 的 Azure Functions 觸發程序來自動建立租用容器。 您也可以手動建立租用容器。 若要自動建立租用容器,請在設定中設定 CreateLeaseContainerIfNotExists 旗標。 分割的租用容器必須有 /id 分割區索引鍵定義。

建立適用於 Azure Cosmos DB 的 Azure Functions 觸發程序

使用適用於 Azure Cosmos DB 的 Azure Functions 觸發程序來建立 Azure 函式的功能,現已支援所有 Azure Functions IDE 和 CLI 整合:

在本機執行觸發程序

您可以使用 Azure Cosmos DB 模擬器在本機執行 Azure Function,以建立和開發無伺服器事件型流程,不需要 Azure 訂用帳戶,也不會產生任何費用。

如果要在雲端測試即時案例,您可以免費試用 Azure Cosmos DB,不需要任何信用卡或 Azure 訂用帳戶。

下一步

您現在可以在下列文章中繼續深入了解變更摘要: