Add custom data to events in Azure Event Hubs

Because an event consists mainly of an opaque set of bytes, it may be difficult for consumers of those events to make informed decisions about how to process them. To allow event publishers to offer better context for consumers, events may also contain custom metadata, in the form of a set of key-value pairs. One common scenario for the inclusion of metadata is to provide a hint about the type of data contained by an event, so that consumers understand its format and can deserialize it appropriately.


This metadata is not used by, or in any way meaningful to, the Event Hubs service; it exists only for coordination between event publishers and consumers.

The following sections show you how to add custom data to events in different programming languages.


var eventBody = new BinaryData("Hello, Event Hubs!");
var eventData = new EventData(eventBody);
eventData.Properties.Add("EventType", "");
eventData.Properties.Add("priority", 1);
eventData.Properties.Add("score", 9.0);

For the full code sample, see Publishing events with custom metadata.


EventData firstEvent = new EventData("EventData Sample 1".getBytes(UTF_8));
firstEvent.getProperties().put("EventType", "");
firstEvent.getProperties().put("priority", 1);
firstEvent.getProperties().put("score", 9.0);

For the full code sample, see Publish events with custom metadata.


event_data = EventData('Message with properties') = {'event-type': '', 'priority': 1, "score": 9.0}

For the full code sample, see Send Event Data batch with properties.


let eventData = { body: "First event", properties: { "event-type": "", "priority": 1, "score": 9.0  } };

Next steps

See the following quickstarts and samples.