title: Azure service bus functions. Receive messages in batch
body: <p>I would like to receive messages from a Azure ServiceBus Topic in batch mode.</p>
  
  <p>Reading <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices</a> it states:</p>
  
  <blockquote>
    <p>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. </p>
  </blockquote>
  
  <p>I have a method:</p>
  
  <pre><code>public static void Run([ServiceBusTrigger("mytopic name", "MySubscription",
  AccessRights.Listen, Connection = TopicService.ConnectionStringName)]
  string messages, TraceWriter logger)
  </code></pre>
  
  <p>This method is working, but it takes 1 message at the time.</p>
  
  <p>According to the Microsoft Documentation, I just could change this to:</p>
  
  <pre><code>public static void Run([ServiceBusTrigger("mytopic name", "MySubscription",
  AccessRights.Listen, Connection = TopicService.ConnectionStringName)]
  string[] messages, TraceWriter logger)
  </code></pre>
  
  <p>And add the following to the host.json file (<a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json</a>):</p>
  
  <pre><code>{
      "aggregator": {
          "batchSize": 10,
          "flushTimeout": "00:00:30"
      }
  }
  </code></pre>
  
  <p>But running the function, I get an exception:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Note: the topic and the subscription have the setting "Enable batched operations" enabled.</p>
  
  <p>What am I missing here?</p>