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?