Send batch events

Sends a new batched message event to an Event Hub. Batching reduces the number of messages that are transmitted by merging information from multiple messages into a single batch of messages. It reduces the number of connections established, and reduces network bandwidth by reducing the number of packet headers that are sent over the network.

Sending a batch of messages isn't that different from sending a single event to an Event Hub. To enable sending batch events to an Event Hub using the REST API, the following requirements must be met:

  1. Implement the logic to create batched messages.

  2. The message body must be a valid JSON payload and follow a convention to describe each message.

  3. Set the Content-Type header to application/vnd.microsoft.servicebus.json.

Request

Method Request URI
POST https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/messages

Request Headers

See Common parameters and headers for headers and parameters that are used by all requests related to Event Hubs.

Additional Request Headers

Request Header Required or Optional Description
Content-Type Required Set to application/vnd.microsoft.servicebus.json.

Request Body

JSON payload that contains the content of multiple messages. For example:

[{"Body":"Message1"},{"Body":"Message2"},{"Body":"Message3"}]  

UserProperties can't be set in headers when sending batch events (they will be ignored). Instead, send them as part of the request body. For example, setting UserProperties in batched events:

[{"Body":"Message1", "UserProperties":{"Alert":"Strong Wind"}}, {"Body":"Message2"}, {"Body":"Message3"}]  

Response

The response includes an HTTP status code, a set of response headers, and a response body.

Response Codes

Code Description
201 Success.
401 Authorization failure.
500 Internal error.

Response Body

If the request is successful, the response body is empty. If the request isn't successful, the body contains an error code and error message.

Examples

Request

Note

You can also use an Azure Active Directory token for the Authorization header as noted in the Common parameters and headers. For example: Authorization: Bearer <Azure AD token>.

POST https://your-namespace.servicebus.windows.net/your-event-hub/messages?timeout=60&api-version=2014-01 HTTP/1.1  
Authorization: SharedAccessSignature sr=your-namespace.servicebus.windows.net&sig=your-sas-key&se=1456197782&skn=RootManageSharedAccessKey  
Content-Type: application/vnd.microsoft.servicebus.json  
Host: your-namespace.servicebus.windows.net  
  
[{"Body":"Message1", "UserProperties":{"Alert":"Strong Wind"}},{"Body":"Message2"},{"Body":"Message3"}]  
  

Response

HTTP/1.1 201 Created  
Content-Type: application/xml; charset=utf-8  
Server: Microsoft-HTTPAPI/2.0  
Date: Tue, 23 Feb 2016 03:22:27 GMT  
Content-Length: 0