简体   繁体   中英

How to listen to DB changes in Azure Cosmos DB from Node App


Azure CosmosDB provides changed feed feature. One can listen to DB changes and run business logic in response.
Is there a way this can be achieved in a Node App?
There is a change feed processor library, but I didn't come across any node SDK to use it.
If any one can provide few pointers how this can be achieved it will be great.

There is currently no equivalent of the Change Feed processor library for Node.

However the Node.js SDK allows you to query the change feed itself manually. You can find an example here: https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed#can-i-read-change-feed-using-javascript

This however means that you will have to write the automated process yourself and you can't be notified only when there is a change. You will have to keep previous and next states and compare what's new and what's not.

You can also achieve automated change feed processing using the Azure Functions trigger which can be used in Node.js (thanks Matias). You can find more info on that here: https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed#using-azure-functions

Also this link has a CosmosDB binding example in js (double thanks Matias): https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb#trigger---javascript-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM