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)?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With