Azure Cosmos change feed Apache Gremlin with Azure functions

Domagoj Bazina 221 Reputation points
2023-03-17T09:32:42.8933333+00:00

Hello everyone!

I would like to know how to "subscribe" to change feed of Azure Cosmos DB based on Apache Gremlin. I've tried to subscribe using Azure Function App (Cosmos DB trigger using Python client), but it didn't log any changes. I used these two guidelines:

  1. https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function
  2. https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?tabs=in-process%2Cfunctionsv2&pivots=programming-language-python
  3. https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed

I've created Function App through Azure portal, and created trigger using Azure VS code. What am I missing here? Is it possible to subscribe to change feed for Apache Gremlin? If it it not possible using Azure Function, can I do it using some sort of script?

Here is the source code:
function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "myConnectionString",
      "databaseName": "graphdb",
      "collectionName": "Persons",
      "createLeaseCollectionIfNotExists": true
    }
  ]
}

_init.py

import logging

import azure.functions as func


def main(documents: func.DocumentList) -> str:
    if documents:
        logging.info('Document id: %s', documents[0]['id'])
    else:
        logging.info("No documents")

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,298 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,448 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,146 Reputation points
    2023-03-21T14:47:38.9+00:00

    Domagoj Bazina Thank you for posting your question in Microsoft Q&A. Currently, Azure Cosmos DB bindings are only supported for NoSQL as mentioned in doc: Create a function triggered by Azure Cosmos DB and https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/change-feed-functions and not supported for Azure Cosmos DB for Apache Gremlin.

    User's image

    So, you need to use language specific client SDK to read change feed and here is Supported APIs and client SDKs list. See Python samples for Gremlin and unfortunately there isn't change feed example for Gremlin and you can use Azure Cosmos DB SQL API client library for Python Samples as reference. If you face any issues, let us know.

    I saw similar feedback regarding this binding Cosmos Gremlin Binding but it was closed since our product team hasn't seen much demand for this API. However, you can submit your feedback on the same thread or open new one in the GitHub repo with your use case.

    I hope this helps with your question and let me know if you have any other questions.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    0 comments No comments