1

Trying to process EventGrid events in batches with .NET function app.

C# isolated process function declaration

  [Function(nameof(HandleBatch))]
  public async Task Run([EventGridTrigger] Azure.Messaging.CloudEvent[] cloudEvents, FunctionContext _)

/*
throws:       

Cannot convert input parameter 'cloudEvents' to type 'Azure.Messaging.CloudEvent[]' from 
type 'System.String'. Error:System.InvalidOperationException: Binding parameters to 
complex objects uses JSON serialization.
*/

When using a single CloudEvent as argument, everything works as expected. Looks like my subscription does not actually send data in batches, at least that's my hunch.

documentation states that you can use CloudEvent[] as parameter type with batching.

Subscription has these settings (deployed with Terraform)

event_delivery_schema = "CloudEventSchemaV1_0"
max_events_per_batch              = 10
preferred_batch_size_in_kilobytes = 64

Installed packages:

 <FrameworkReference Include="Microsoft.AspNetCore.App" />
 <PackageReference Include="Azure.Identity" Version="1.13.2" />
 <PackageReference Include="Azure.Storage.Blobs" Version="12.24.0" />
 <PackageReference Include="Dapper" Version="2.1.66" />
 <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
 <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
 <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
 <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.EventGrid" Version="3.4.2" />
 <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
 <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
 <PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
 <PackageReference Include="Microsoft.Extensions.Http" Version="9.0.4" />

The topic is a System Topic connected to Blob Storage, if that makes a difference.

Anybody had luck enabling batching?

1 Answer 1

1

After some detective work, I stumbled upon the JSON files generated by deploy in the portal and there was a setting for cardinality in that specific function. That gave me a hint that something in the function declaration must have information about batching.

Then intellisense showed me that EventGridTriggerAttribute has an IsBatched boolean parameter.

So changing parameters like this enabled batch processing:

public async Task Run([EventGridTrigger(IsBatched = true)] CloudEvent[] cloudEvents, FunctionContext _)

Would have been nice of MS to include this in their docs about batching. Hope this helps someone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.