Search code examples
azureazure-eventhub

Send Batch events to Event Hub using REST API


I am able to send events to Event Hub as a batch using the Nuget package Azure.Messaging.EventHubs.But I want to use REST API. I am able to send single events to Event Hub using REST API using Postman. But as per documentation if I need to send batch events in REST API I need add header Content-Type:application/vnd.microsoft.servicebus.json and Also the message should be enclosed with the "Body" like [{"Body":"Message1"},{"Body":"Message2"},{"Body":"Message3"}]

So if I need to send json as event then should I create a json string and send it?

Sample:

   [
   {
      "Body":"{\"ID\":\"1\",\"Name\":\"abc1\"}"
   },
   {
      "Body":"{\"ID\":\"2\",\"Name\":\"def1\"}"
   },
   {
      "Body":"{\"ID\":\"3\",\"Name\":\"xyz1\"}"
   }
   ]

OR is there any other option to send event as Batch using the REST API to Event Hub.


Solution

  • "Body" is a string content then yes, you must escape your JSON content first. Your sample looks OK to me.