Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions: ICollector<T> vs IAsyncCollector<T>

Tags:

What's the difference between ICollector<T> and IAsyncCollector<T> in Azure Functions when writing C# functions (also applies to WebJobs)?

I understand from the samples that these are interfaces I can use to bind a function parameter to an output binding. I also understand that the two interfaces have non-async and async method signatures accordingly (i.e. ICollector<T>.Add(item) and IAsyncCollector<T>.AddAsync(item)). But what do they do under the covers? Do they actually post data to the output binding, or is it internally buffered and flushed at the end of function execution (in which case, why would there by an AddAsync method)?

like image 444
Chris Gillum Avatar asked Nov 22 '16 02:11

Chris Gillum


People also ask

What is input and output binding in Azure functions?

Azure Function BindingsAn input binding is the data that your function receives. An output binding is the data that your function sends. Unlike a trigger, a function can have multiple input and output bindings.

What are the types of bindings supported by Azure functions?

Binding to a function is a way of declaratively connecting another resource to the function; bindings may be connected as input bindings, output bindings, or both. Data from bindings is provided to the function as parameters. You can mix and match different bindings to suit your needs.

What is the difference between Azure functions and WebJobs?

Summary. Azure Functions offers more developer productivity than Azure App Service WebJobs does. It also offers more options for programming languages, development environments, Azure service integration, and pricing. For most scenarios, it's the best choice.

How many types of Azure functions are there?

There are currently four durable function types in Azure Functions: activity, orchestrator, entity, and client. The rest of this section goes into more details about the types of functions involved in an orchestration.


1 Answers

ICollector<T>.Add(item) will always perform the add operation against the underlying service immediately. E.g. the implementation for the Queue binding will enqueue messages immediately as they are added.

IAsyncCollector<T>.AddAsync(item) behavior varies from binding to binding, based on whether the underlying service supports batching. In such cases, AddAsync may only actually save the added items to be flushed later by the corresponding IAsyncCollector<T>.FlushAsync method. When a function completes successfully FlushAsync will be called automatically. You can allow the auto-flush behavior to flush for you, or you may choose to call FlushAsync manually in your function as you need to.

Batching can allow the binding to interact with the underlying service in the most efficient way possible. E.g. for Azure Tables, multiple entities can be updated/persisted in a single batch operation.

like image 181
mathewc Avatar answered Oct 04 '22 03:10

mathewc