public class EventData extends Object
EventData
.
Here's how AMQP message sections map to EventData
. For reference, the specification can be found here:
AMQP 1.0 specification
EventData.getProperties()
- AMQPMessage.ApplicationProperties sectionEventData.getBody()
- if AMQPMessage.Body has Data section
Serializing a received EventData
with AMQP sections other than ApplicationProperties (with primitive Java
types) and Data section is not supported.
Constructor and Description |
---|
EventData(byte[] body)
Creates an event containing the
body . |
EventData(ByteBuffer body)
Creates an event containing the
body . |
EventData(String body)
Creates an event by encoding the
body using UTF-8 charset. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
byte[] |
getBody()
Gets the actual payload/data wrapped by EventData.
|
String |
getBodyAsString()
Returns event data as UTF-8 decoded string.
|
Instant |
getEnqueuedTime()
Gets the instant, in UTC, of when the event was enqueued in the Event Hub partition.
|
Long |
getOffset()
Gets the offset of the event when it was received from the associated Event Hub partition.
|
String |
getPartitionKey()
Gets the partition hashing key if it was set when originally publishing the event.
|
Map<String,Object> |
getProperties()
Gets the set of free-form event properties which may be used for passing metadata associated with the event with
the event body during Event Hubs operations.
|
Long |
getSequenceNumber()
Gets the sequence number assigned to the event when it was enqueued in the associated Event Hub partition.
|
Map<String,Object> |
getSystemProperties()
Properties that are populated by Event Hubs service.
|
int |
hashCode() |
public EventData(byte[] body)
body
.body
- The data to set for this event.NullPointerException
- if body
is null
.public EventData(ByteBuffer body)
body
.body
- The data to set for this event.NullPointerException
- if body
is null
.public EventData(String body)
body
using UTF-8 charset.body
- The string that will be UTF-8 encoded to create an event.NullPointerException
- if body
is null
.public Map<String,Object> getProperties()
properties()
is to associate
serialization hints for the EventData.getBody()
as an aid to consumers who wish to deserialize the binary data.
Adding serialization hint using getProperties()
In the sample, the type of telemetry is indicated by adding an application property with key "eventType".
TelemetryEvent telemetry = new TelemetryEvent("temperature", "37"); byte[] serializedTelemetryData = telemetry.toString().getBytes(UTF_8);EventData
eventData = newEventData
(serializedTelemetryData); eventData.getProperties().put("eventType", TelemetryEvent.class.getName());
EventData
.public Map<String,Object> getSystemProperties()
EventData
.public byte[] getBody()
If the means for deserializing the raw data is not apparent to consumers, a common technique is to make use of
EventData.getProperties()
when creating the event, to associate serialization hints as an aid to consumers who
wish to deserialize the binary data.
public String getBodyAsString()
public Long getOffset()
EventData
.null
if the EventData
was not received from Event Hubs service.public String getPartitionKey()
EventData
.null
if the EventData
was not received from Event
Hubs service or there was no partition key set when the event was sent to the Event Hub.public Instant getEnqueuedTime()
EventData
.null
if the EventData
was not received from Event Hubs service.public Long getSequenceNumber()
EventData
.null
if the EventData
was not received from Event
Hubs service.Copyright © 2019 Microsoft Corporation. All rights reserved.