I would like to receive messages from a Azure ServiceBus Topic in batch mode.
Reading https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices it states:
For C# functions you can change the type to a strongly-typed array. For example, instead of EventData sensorEvent the method signature could be EventData[] sensorEvent.
I have a method:
public static void Run([ServiceBusTrigger("mytopic name", "MySubscription",
AccessRights.Listen, Connection = TopicService.ConnectionStringName)]
string messages, TraceWriter logger)
This method is working, but it takes 1 message at the time.
According to the Microsoft Documentation, I just could change this to:
public static void Run([ServiceBusTrigger("mytopic name", "MySubscription",
AccessRights.Listen, Connection = TopicService.ConnectionStringName)]
string[] messages, TraceWriter logger)
And add the following to the host.json file (https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json):
{
"aggregator": {
"batchSize": 10,
"flushTimeout": "00:00:30"
}
}
But running the function, I get an exception:
mscorlib: Exception while executing function: MyFunction. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'messages'. System.Runtime.Serialization: There was an error deserializing the object of type System.String[]. The input source is not correctly formatted. System.Runtime.Serialization: The input source is not correctly formatted.
Note: the topic and the subscription have the setting "Enable batched operations" enabled.
What am I missing here?