简体   繁体   English

如何通过ChangeFeed获得有关Cosmos DB中更改的通知?

[英]How to get notified about change in Cosmos DB through ChangeFeed?

When I'm browsing through MSDN documentation all I can see is "observing" changes on ChangeFeed. 当我浏览MSDN文档时,我所看到的只是在ChangeFeed上“观察”更改。 Even the first diagram there shows only direction from external services (Storm, Azure Functions, etc.) towards ChangeFeed. 即使是那里的第一个图,也仅显示了外部服务(Storm,Azure Functions等) ChangeFeed的方向

Is there any pattern that (is not obvious for me) we can use for getting notified about changes in Cosmos DB over ChangeFeed? 是否有任何模式(对我来说并不明显)可用于通过ChangeFeed通知有关Cosmos DB中的更改? Or there really needs to be support built-in eg Azure Functions to get this "PUSH" scenario working? 还是真的需要内置支持(例如Azure功能)才能使这种“推送”方案起作用?

Thanks a lot 非常感谢

The Azure Cosmos DB Change Feed processor library was released recently in order to make listening to the Azure Cosmos DB change feed a bit easier. 最近发布了Azure Cosmos DB更改Feed处理器库 ,以使收听Azure Cosmos DB更改Feed更加容易。 It handles automatic lease management for a set of change feed listening "workers" to read across Cosmos DB partitions; 它为一组变更提要侦听“工作人员”处理自动租赁管理,以跨Cosmos DB分区进行读取。 enabling you to easily scale out the set of change feed listening workers. 使您能够轻松地扩展一组变更提要监听工作人员。 Using this, you can build a pub/sub model on top of the consumer of the library. 使用此功能,您可以在库的使用者之上构建发布/订阅模型。

With that said, integration between Azure Cosmos DB's change feed + Azure Functions is on the Azure Cosmos DB roadmap (as of current date - 8/5/17) to help make pushing changes even easier to accomplish. 话虽如此,Azure Cosmos DB路线图(截至当前日期-8/5/17)上集成了Azure Cosmos DB的变更摘要和Azure功能之间的集成,以帮助推动变更更容易实现。 No specific dates have been announced for this yet; 目前尚未宣布具体日期。 but do stay tuned. 但请继续关注。

Wanted to provide some updates to this question since the Azure Functions support has been added by now and the Change Feed Processor library has been fully integrated in the Azure SQL SDK for Java/.NET. 想要提供此问题的一些更新,因为到目前为止已经添加了Azure功能支持,并且Change Feed Processor库已完全集成在Java / .NET的Azure SQL SDK中。

It is really easy to get notifications from a Change Feed, without using Azure Functions, through the usage of the ChangeFeedProcessor API - but bear in mind, it is not really a " PUSH " scenario as the Change Feed is queried in a polling fashion by the client! 通过使用ChangeFeedProcessor API可以很容易地从Change Feed中获取通知,而无需使用Azure Functions-但请记住,由于更改Feed是通过轮询方式查询的,因此这并不是一个“ 推送 ”方案客户端!

The code would look like this: 代码如下所示:

public static void startChangeFeedProcessor(String hostName, CosmosContainer feedContainer, CosmosContainer leaseContainer) {
  ChangeFeedProcessor.Builder()
    .hostName(hostName)
    .feedContainer(feedContainer)
    .leaseContainer(leaseContainer)
    .options(new ChangeFeedProcessorOptions().leasePrefix("my-lease-prefix")) //not required
    .handleChanges(docs -> {
        for (CosmosItemProperties document : docs) {
            System.out.println("Read document from Change Feed: " + document.toJson(SerializationFormattingPolicy.INDENTED));
        }
    })
    .build()
    .start()
    .subscribe();
}

You can check out more in-depth details about the Azure CosmosDB Change Feed here . 您可以在此处查看有关Azure CosmosDB更改Feed的更深入的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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