Show / Hide Table of Contents

Class EventData

An Event Hubs event, encapsulating a set of data and its associated metadata.

Inheritance
Azure.Messaging.MessageContent
EventData
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Messaging.EventHubs.dll
Syntax
public class EventData : Azure.Messaging.MessageContent

Constructors

EventData()

Initializes a new instance of the EventData class.

Declaration
public EventData ();

EventData(AmqpAnnotatedMessage)

Initializes a new instance of the EventData class.

Declaration
public EventData (Azure.Core.Amqp.AmqpAnnotatedMessage amqpMessage);
Parameters
Azure.Core.Amqp.AmqpAnnotatedMessage amqpMessage

The Azure.Core.Amqp.AmqpAnnotatedMessage on which to base the event.

EventData(BinaryData)

Initializes a new instance of the EventData class.

Declaration
public EventData (BinaryData eventBody);
Parameters
System.BinaryData eventBody

The raw data as binary to use as the body of the event.

EventData(ReadOnlyMemory<Byte>)

Initializes a new instance of the EventData class.

Declaration
public EventData (ReadOnlyMemory<byte> eventBody);
Parameters
System.ReadOnlyMemory<System.Byte> eventBody

The raw data to use as the body of the event.

EventData(String)

Initializes a new instance of the EventData class.

Declaration
public EventData (string eventBody);
Parameters
System.String eventBody

The data to use as the body of the event. This will be represented as a set UTF-8 encoded bytes.

EventData(BinaryData, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, Int64, Int64, DateTimeOffset, String)

Obsolete.

Initializes a new instance of the EventData class.

Declaration
[System.ComponentModel.EditorBrowsable]
[System.Obsolete("The Event Hubs service does not guarantee a numeric offset for all resource configurations.  Please use the overload with a string-based offset instead.", false)]
protected EventData (BinaryData eventBody, System.Collections.Generic.IDictionary<string,object> properties = null, System.Collections.Generic.IReadOnlyDictionary<string,object> systemProperties = null, long sequenceNumber = -9223372036854775808, long offset = -9223372036854775808, DateTimeOffset enqueuedTime = null, string partitionKey = null);
Parameters
System.BinaryData eventBody

The raw data to use as the body of the event.

System.Collections.Generic.IDictionary<System.String,System.Object> properties

The set of free-form event properties to send with the event.

System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object> systemProperties

The set of system properties received from the Event Hubs service.

System.Int64 sequenceNumber

The sequence number assigned to the event when it was enqueued in the associated Event Hub partition.

System.Int64 offset

The offset of the event when it was received from the associated Event Hub partition.

System.DateTimeOffset enqueuedTime

The date and time, in UTC, of when the event was enqueued in the Event Hub partition.

System.String partitionKey

The partition hashing key associated with the event when it was published.

Remarks

This constructor is obsolete and has been replaced by EventData(BinaryData, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, String, Int64, String, DateTimeOffset). It should no longer be called.

This overload was previously intended for mocking in support of testing efforts. It is recommended that it not be used in production scenarios, as it allows setting of data that is broker-owned and is only meaningful on events that have been read from the Event Hubs service.

SSS

EventData(BinaryData, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, Int64, String, DateTimeOffset, String)

Initializes a new instance of the EventData class.

Declaration
[System.ComponentModel.EditorBrowsable]
protected EventData (BinaryData eventBody, System.Collections.Generic.IDictionary<string,object> properties = null, System.Collections.Generic.IReadOnlyDictionary<string,object> systemProperties = null, long sequenceNumber = -9223372036854775808, string offsetString = null, DateTimeOffset enqueuedTime = null, string partitionKey = null);
Parameters
System.BinaryData eventBody

The raw data to use as the body of the event.

System.Collections.Generic.IDictionary<System.String,System.Object> properties

The set of free-form event properties to send with the event.

System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object> systemProperties

The set of system properties received from the Event Hubs service.

System.Int64 sequenceNumber

The sequence number assigned to the event when it was enqueued in the associated Event Hub partition.

System.String offsetString

The offset of the event when it was received from the associated Event Hub partition.

System.DateTimeOffset enqueuedTime

The date and time, in UTC, of when the event was enqueued in the Event Hub partition.

System.String partitionKey

The partition hashing key associated with the event when it was published.

Remarks

This constructor exists only for backwards compatibility and has been replaced by EventData(BinaryData, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, String, Int64, String, DateTimeOffset). It should no longer be called.

This overload was previously intended for mocking in support of testing efforts. It is recommended that it not be used in production scenarios, as it allows setting of data that is broker-owned and is only meaningful on events that have been read from the Event Hubs service.

SSS

EventData(ReadOnlyMemory<Byte>, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, Int64, Int64, DateTimeOffset, String)

Obsolete.

Initializes a new instance of the EventData class.

Declaration
[System.ComponentModel.EditorBrowsable]
[System.Obsolete("The Event Hubs service does not guarantee a numeric offset for all resource configurations.  Please use the overload with a string-based offset instead.")]
protected EventData (ReadOnlyMemory<byte> eventBody, System.Collections.Generic.IDictionary<string,object> properties = null, System.Collections.Generic.IReadOnlyDictionary<string,object> systemProperties = null, long sequenceNumber = -9223372036854775808, long offset = -9223372036854775808, DateTimeOffset enqueuedTime = null, string partitionKey = null);
Parameters
System.ReadOnlyMemory<System.Byte> eventBody

The raw data to use as the body of the event.

System.Collections.Generic.IDictionary<System.String,System.Object> properties

The set of free-form event properties to send with the event.

System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object> systemProperties

The set of system properties received from the Event Hubs service.

System.Int64 sequenceNumber

The sequence number assigned to the event when it was enqueued in the associated Event Hub partition.

System.Int64 offset

The offset of the event when it was received from the associated Event Hub partition.

System.DateTimeOffset enqueuedTime

The date and time, in UTC, of when the event was enqueued in the Event Hub partition.

System.String partitionKey

The partition hashing key associated with the event when it was published.

Remarks

This constructor is obsolete and has been replaced by EventData(BinaryData, IDictionary<String,Object>, IReadOnlyDictionary<String,Object>, String, Int64, String, DateTimeOffset). It should no longer be called.

This overload was previously intended for mocking in support of testing efforts. It is recommended that it not be used in production scenarios, as it allows setting of data that is broker-owned and is only meaningful on events that have been read from the Event Hubs service.

Properties

Body

The data associated with the event.

Declaration
[System.ComponentModel.EditorBrowsable]
public ReadOnlyMemory<byte> Body { get; }
Property Value
System.ReadOnlyMemory<System.Byte>

Remarks

This member exists only to preserve backward compatibility. It is recommended to prefer the EventBody where possible in order to take advantage of additional functionality and improved usability for common scenarios.

See Also
EventBody

BodyAsStream

The data associated with the event, in stream form.

Declaration
[System.ComponentModel.EditorBrowsable]
public System.IO.Stream BodyAsStream { get; }
Property Value
System.IO.Stream

A System.IO.Stream containing the raw data representing the EventBody of the event. The caller is assumed to have ownership of the stream, including responsibility for managing its lifespan and ensuring proper disposal.

Remarks

This member exists only to preserve backward compatibility. It is recommended to prefer the EventBody where possible in order to take advantage of additional functionality and improved usability for common scenarios.

See Also
EventBody

ContentType

A MIME type describing the data contained in the EventBody, intended to allow consumers to make informed decisions for inspecting and processing the event.

Declaration
public string ContentType { get; set; }
Property Value
System.String

The MIME type of the EventBody content; when unknown, it is recommended that this value should not be set. When the body is known to be truly opaque binary data, it is recommended that "application/octet-stream" be used.

Remarks

The ContentType is managed by the application and is intended to allow coordination between event producers and consumers.

Event Hubs does not read, generate, or populate this value. It does not influence how Event Hubs stores or manages the event.

ContentTypeCore

This member is intended to allow the string-based ContentType in this class to be translated to/from the Azure.Core.ContentType type used by the Azure.Messaging.MessageContent base class.

Declaration
[System.ComponentModel.EditorBrowsable]
protected override Nullable<Azure.Core.ContentType> ContentTypeCore { get; set; }
Property Value
System.Nullable<Azure.Core.ContentType>

CorrelationId

An application-defined value that represents the context to use for correlation across one or more operations. The identifier is a free-form value and may reflect a unique identity or a shared data element with significance to the application.

Declaration
public string CorrelationId { get; set; }
Property Value
System.String

Remarks

The CorrelationId is intended to enable tracing of data within an application, such as an event's path from producer to consumer.

Event Hubs does not read, generate, or populate this value. It does not influence Event Hubs telemetry, distributed tracing, or logging.

Data

Hidden property that shadows the EventBody property. This is added in order to inherit from Azure.Messaging.MessageContent.

Declaration
[System.ComponentModel.EditorBrowsable]
public override BinaryData Data { get; set; }
Property Value
System.BinaryData

EnqueuedTime

The date and time, in UTC, of when the event was enqueued in the Event Hub partition.

Declaration
public DateTimeOffset EnqueuedTime { get; }
Property Value
System.DateTimeOffset

This value is read-only and will only be populated for events that have been read from Event Hubs. The default value when not populated is default(DateTimeOffset).

EventBody

The data associated with the event, in System.BinaryData form, providing support for a variety of data transformations and Azure.Core.Serialization.ObjectSerializer integration.

Declaration
public BinaryData EventBody { get; set; }
Property Value
System.BinaryData

Remarks

If the means for deserializing the raw data is not apparent to consumers, a common technique is to set the ContentType or make use of the Properties to associate serialization hints to aid consumers who wish to deserialize the binary data.

See Also
Properties

IsReadOnly

Hidden property that indicates that the EventData is not read-only. This is part of the Azure.Messaging.MessageContent abstraction.

Declaration
[System.ComponentModel.EditorBrowsable]
public override bool IsReadOnly { get; }
Property Value
System.Boolean

MessageId

An application-defined value that uniquely identifies the event. The identifier is a free-form value and can reflect a GUID or an identifier derived from the application context.

Declaration
public string MessageId { get; set; }
Property Value
System.String

The application identifier assigned to the event.

Remarks

The MessageId is intended to allow coordination between event producers and consumers in applications.

Event Hubs does not read, generate, or populate this value. It does not influence how Event Hubs identifies the event.

Offset

Obsolete. A numeric representation of the offset of an event when it was received from the associated Event Hub partition.

Declaration
[System.ComponentModel.EditorBrowsable]
[System.Obsolete("The Event Hubs service does not guarantee a numeric offset for all resource configurations.  Please use 'OffsetString' instead.", false)]
public long Offset { get; }
Property Value
System.Int64

This value is obsolete and should no longer be used. Please use OffsetString instead.

OffsetString

The offset of the event when it was received from the associated Event Hub partition.

Declaration
public string OffsetString { get; }
Property Value
System.String

This value is read-only and will only be populated for events that have been read from Event Hubs. The default value when not populated is null.

PartitionKey

The partition hashing key applied to the batch that the associated EventData, was published with.

Declaration
public string PartitionKey { get; }
Property Value
System.String

This value is read-only and will only be populated for events that have been read from Event Hubs. The default value when not populated is null.

Remarks

To specify a partition key when publishing an event, specify your key in the SendEventOptions and use the SendAsync(IEnumerable<EventData>, SendEventOptions, CancellationToken) overload.

Properties

The set of free-form properties which may be used for associating metadata with the event that is meaningful within the application context.

Declaration
public System.Collections.Generic.IDictionary<string,object> Properties { get; }
Property Value
System.Collections.Generic.IDictionary<System.String,System.Object>

Examples

       var eventData = new EventData(serializedTelemetryData);
       eventData.Properties["eventType"] = "com.microsoft.azure.monitoring.EtlEvent";
Remarks

A common use case for Properties is to associate serialization hints for the EventBody as an aid to consumers who wish to deserialize the binary data when the ContentType alone does not offer sufficient context.

The following types are supported:

  • string
  • bool
  • byte
  • sbyte
  • short
  • ushort
  • int
  • uint
  • long
  • ulong
  • float
  • decimal
  • double
  • char
  • Guid
  • DateTime
  • DateTimeOffset
  • Stream
  • Uri
  • TimeSpan
  • byte[]
Exceptions
System.Runtime.Serialization.SerializationException

Occurs when the EventData is serialized for transport when an unsupported type is used as a property.

SequenceNumber

The sequence number assigned to the event when it was enqueued in the associated Event Hub partition.

Declaration
public long SequenceNumber { get; }
Property Value
System.Int64

This value is read-only and will only be populated for events that have been read from Event Hubs. The default value when not populated is System.Int64.MinValue.

SystemProperties

The set of free-form event properties which were provided by the Event Hubs service to pass metadata associated with the event or associated Event Hubs operation.

Declaration
public System.Collections.Generic.IReadOnlyDictionary<string,object> SystemProperties { get; }
Property Value
System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object>

These properties are read-only and will only be populated for events that have been read from Event Hubs. The default value when not populated is an empty set.

Methods

Equals(Object)

Determines whether the specified System.Object is equal to this instance.

Declaration
[System.ComponentModel.EditorBrowsable]
public override bool Equals (object obj);
Parameters
System.Object obj

The System.Object to compare with this instance.

Returns
System.Boolean

true if the specified System.Object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

Declaration
[System.ComponentModel.EditorBrowsable]
public override int GetHashCode ();
Returns
System.Int32

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

GetRawAmqpMessage()

The event representation in the AMQP protocol format. This allows access to protocol information that is not relevant to Event Hubs and is not exposed by EventData directly. This information can be helpful when exchanging data with other message brokers or clients that do not use one of the Event Hubs SDKs.

Declaration
public Azure.Core.Amqp.AmqpAnnotatedMessage GetRawAmqpMessage ();
Returns
Azure.Core.Amqp.AmqpAnnotatedMessage

The event, as an Azure.Core.Amqp.AmqpAnnotatedMessage.

Remarks

Manipulating the raw AMQP message is an advanced operation recommended only for those with knowledge of the AMQP protocol and have a need outside of the normal operation of Event Hubs, such as inter-operating with another message broker.

When making direct changes to the AMQP message, it is possible to cause issues with the Event Hubs client library, such as invalidating the size calculations performed by the EventDataBatch resulting in a batch that cannot be successfully published.

ToString()

Converts the instance to string representation.

Declaration
[System.ComponentModel.EditorBrowsable]
public override string ToString ();
Returns
System.String

A System.String that represents this instance.

Back to top Azure SDK for .NET