EventData Interface

public interface EventData

The data structure encapsulating the Event being sent-to and received-from EventHubs. Each EventHubs partition can be visualized as a Stream of EventData.

Serializing a received EventData with AMQP sections other than ApplicationProperties (with primitive java types) and Data section is not supported.

Here's how AMQP message sections map to EventData. Here's the reference used for AMQP 1.0 specification: http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-complete-v1.0-os.pdf

i.   getProperties() - AMQPMessage.ApplicationProperties section
ii.  getBytes() - if AMQPMessage.Body has Data section
iii. getObject() - if AMQPMessage.Body has AMQPValue or AMQPSequence sections
While using client libraries released by Microsoft Azure EventHubs, sections (i) and (ii) alone are sufficient. Section (iii) is used for advanced scenarios, where the sending application uses third-party AMQP library to send the message to EventHubs and the receiving application uses this client library to receive EventData.

Method Summary

Modifier and Type Method and Description
EventData create(final byte[] data)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Sample Code:

EventData eventData = EventData.create(telemetryEventBytes);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");
partitionSender.Send(eventData);

EventData create(final byte[] data, final int offset, final int length)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Illustration:

EventData eventData = EventData.create(telemetryEventBytes, offset, length);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");

partitionSender.Send(eventData);

</code></pre></p>

EventData create(final ByteBuffer buffer)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Illustration:

EventData eventData = EventData.create(telemetryEventByteBuffer);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");

   partitionSender.Send(eventData);

</code></pre></p>

byte [] getBytes()

Get Actual Payload/Data wrapped by EventData.

null if the body of the message has other inter-operable AMQP messages, whose body does not represent byte[]. In that case use getObject().

Object getObject()

Use this method only if, the sender could be sending messages using third-party AMQP libraries.

If all the senders of EventHub use client libraries released and maintained by Microsoft Azure EventHubs, use getBytes() method.

Get the value of AMQP messages' Body section on the received EventData.

If the AMQP message Body is always guaranteed to have Data section, use getBytes() method.

Binary if the Body is Data section

List if the Body is AmqpSequence

package org.apache.qpid.proton.amqp contains various AMQP types that could be returned.

Map<String, Object> getProperties()

Application property bag

EventData.SystemProperties getSystemProperties()

SystemProperties that are populated by EventHubService.

As these are populated by Service, they are only present on a Received EventData.

Usage:

Method Details

create

public static EventData create(final byte[] data)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Sample Code:

EventData eventData = EventData.create(telemetryEventBytes);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");
partitionSender.Send(eventData);

Parameters:

data - the actual payload of data in bytes to be Sent to EventHubs.

Returns:

EventData the created EventData to send to EventHubs.

create

public static EventData create(final byte[] data, final int offset, final int length)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Illustration:

EventData eventData = EventData.create(telemetryEventBytes, offset, length);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");

partitionSender.Send(eventData);

</code></pre></p>

Parameters:

data - the byte[] where the payload of the Event to be sent to EventHubs is present
offset - Offset in the byte[] to read from ; inclusive index
length - length of the byte[] to be read, starting from offset

Returns:

EventData the created EventData to send to EventHubs.

create

public static EventData create(final ByteBuffer buffer)

Construct EventData to Send to EventHubs. Typical pattern to create a Sending EventData is:

i.	Serialize the sending ApplicationEvent to be sent to EventHubs into bytes.
ii.	If complex serialization logic is involved (for example: multiple types of data) - add a Hint using the getProperties() for the Consumer.

Illustration:

EventData eventData = EventData.create(telemetryEventByteBuffer);
eventData.getProperties().put("eventType", "com.microsoft.azure.monitoring.EtlEvent");

   partitionSender.Send(eventData);

</code></pre></p>

Parameters:

buffer - ByteBuffer which references the payload of the Event to be sent to EventHubs

Returns:

EventData the created EventData to send to EventHubs.

getBytes

public byte [] getBytes()

Get Actual Payload/Data wrapped by EventData.

null if the body of the message has other inter-operable AMQP messages, whose body does not represent byte[]. In that case use getObject().

Returns:

byte[] of the actual data

getObject

public Object getObject()

Use this method only if, the sender could be sending messages using third-party AMQP libraries.

If all the senders of EventHub use client libraries released and maintained by Microsoft Azure EventHubs, use getBytes() method.

Get the value of AMQP messages' Body section on the received EventData.

If the AMQP message Body is always guaranteed to have Data section, use getBytes() method.

Binary if the Body is Data section

List if the Body is AmqpSequence

package org.apache.qpid.proton.amqp contains various AMQP types that could be returned.

Returns:

returns the Object which could represent either Data or AmqpValue or AmqpSequence.

getProperties

public Map getProperties()

Application property bag

Returns:

returns Application properties

getSystemProperties

public SystemProperties getSystemProperties()

SystemProperties that are populated by EventHubService.

As these are populated by Service, they are only present on a Received EventData.

Usage:

Returns:

an encapsulation of all SystemProperties appended by EventHubs service into EventData. null if the EventData is not received and is created by the public constructors.

Applies to