简体   繁体   English

azure 函数中 Cosmos DB 的输出绑定中如何管理并发?

[英]How is concurrency managed in output binding for Cosmos DB in azure function?

I have a function app and it has 2 functions in it, Function1 which is an HTTPTrigger function and runs when an HTTP call is hit on it, it then sends the payload to service bus and completes its execution.我有一个函数应用程序,其中有 2 个函数, Function1是一个 HTTPTrigger 函数,当 HTTP 调用被命中时运行,然后它将有效负载发送到服务总线并完成其执行。

Another function Function2 runs when something is published in the service bus queue and it then checks the corresponding data in the CosmosDB and if it is already present then it updates some keys in it otherwise, it creates a new document in the database.另一个函数Function2在服务总线队列中发布某些内容时运行,然后它检查 CosmosDB 中的相应数据,如果它已经存在,则更新其中的一些键,否则,它会在数据库中创建一个新文档。

The problem I am facing is that if 2 requests are made on the HTTPTrigger function then only one of those are executed, I want to check if there is a way I can look for concurrency in the CosmosDB operation.我面临的问题是,如果在 HTTPTrigger 函数上发出 2 个请求,那么只有其中一个被执行,我想检查是否有一种方法可以在 CosmosDB 操作中查找并发性。

The update operation on cosmosDB is through the output binding. cosmosDB 上的更新操作是通过输出绑定进行的。

context.bindings.outputDocument = updatedDocument

Output binding just performs an Upsert operation.输出绑定只执行一个 Upsert 操作。 If you Upsert the same document (same id and partition key value) twice, it's still a single document (first Upsert creates the document, second Upsert updates it).如果您 Upsert 两次相同的文档(相同的 id 和分区键值),它仍然是一个文档(第一次 Upsert 创建文档,第二次 Upsert 更新它)。

Concurrency is based on the Triggers and how they execute, in your case, it depends on the HTTP Trigger and how it handles concurrent requests.并发性基于触发器及其执行方式,在您的情况下,它取决于 HTTP 触发器及其处理并发请求的方式。 Either the Upserts are sequential or concurrent, but from the Output Binding perspective it doesn't matter, each is an independent Upsert call. Upsert 要么是顺序的,要么是并发的,但从输出绑定的角度来看,这并不重要,每个都是独立的 Upsert 调用。

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

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