Table of Contents

Class EventHubClient

Namespace
Microsoft.ServiceBus.Messaging
Assembly
Microsoft.ServiceBus.dll

An anchor class used to send and receive events to and from an Event Hub.

public abstract class EventHubClient : ClientEntity
Inheritance
EventHubClient
Inherited Members

Properties

Path

Gets the path of the Event Hub.

public string Path { get; }

Property Value

string

The path of the Event Hub.

PrefetchCount

Gets or sets the number of events that any receive operation will actively cache. By default, this value is inherited from MessagingFactory if the current instance is created from the factory method. Otherwise, the default value is 10,000.

public int PrefetchCount { get; set; }

Property Value

int

The number of messages that the message receiver can simultaneously request.

Exceptions

ArgumentOutOfRangeException

Thrown if the value is less than the minimum required value of 10.

PrefetchSizeInBytes

public long? PrefetchSizeInBytes { get; set; }

Property Value

long?

Methods

Create(string)

Creates a new instance of the EventHubClient using a connection string from the application configuration settings.

public static EventHubClient Create(string path)

Parameters

path string

The path to the Event Hub.

Returns

EventHubClient

The newly created Event Hub client object.

CreateFromConnectionString(string)

public static EventHubClient CreateFromConnectionString(string connectionString)

Parameters

connectionString string

Returns

EventHubClient

CreateFromConnectionString(string, string)

Creates a new instance of the Event Hub client using the specified connection string.

public static EventHubClient CreateFromConnectionString(string connectionString, string path)

Parameters

connectionString string

The connection string to be used.

path string

The path to the Event Hub.

Returns

EventHubClient

The newly created EventHubClient object.

CreatePartitionedSender(string)

Creates an Event Hubs sender for the specified Event Hubs partition.

public EventHubSender CreatePartitionedSender(string partitionId)

Parameters

partitionId string

The ID of the partition.

Returns

EventHubSender

Returns the EventHubSender object.

CreatePartitionedSenderAsync(string)

Asynchronous version of CreatePartitionedSender(string).

public Task<EventHubSender> CreatePartitionedSenderAsync(string partitionId)

Parameters

partitionId string

The ID of the partition.

Returns

Task<EventHubSender>

Returns Task<TResult>.

CreateSender(string)

public EventHubSender CreateSender(string publisher)

Parameters

publisher string

Returns

EventHubSender

CreateSenderAsync()

Creates the event hub sender. This method is for internal use, and not meant to be called from user code.

protected abstract Task<MessageSender> CreateSenderAsync()

Returns

Task<MessageSender>

The task representing the asynchronous operation.

CreateSenderAsync(string)

public Task<EventHubSender> CreateSenderAsync(string publisher)

Parameters

publisher string

Returns

Task<EventHubSender>

GetConsumerGroup(string)

Returns the consumer group with the specified name, for the receive operation of event data.

public EventHubConsumerGroup GetConsumerGroup(string groupName)

Parameters

groupName string

The name of the group.

Returns

EventHubConsumerGroup

A EventHubConsumerGroup instance, corresponding to the consumer group.

GetDefaultConsumerGroup()

Returns the default consumer group, for the receive operation of event data.

public EventHubConsumerGroup GetDefaultConsumerGroup()

Returns

EventHubConsumerGroup

The default EventHubConsumerGroup.

GetPartitionRuntimeInformation(string)

public virtual PartitionRuntimeInformation GetPartitionRuntimeInformation(string partitionId)

Parameters

partitionId string

Returns

PartitionRuntimeInformation

GetPartitionRuntimeInformationAsync(string)

public virtual Task<PartitionRuntimeInformation> GetPartitionRuntimeInformationAsync(string partitionId)

Parameters

partitionId string

Returns

Task<PartitionRuntimeInformation>

GetRuntimeInformation()

Retrieves Event Hubs runtime information, which is required for creating EventHubSender or EventHubReceiver objects.

public virtual EventHubRuntimeInformation GetRuntimeInformation()

Returns

EventHubRuntimeInformation

Returns EventHubRuntimeInformation.

GetRuntimeInformationAsync()

Asynchronous version of GetRuntimeInformation().

public virtual Task<EventHubRuntimeInformation> GetRuntimeInformationAsync()

Returns

Task<EventHubRuntimeInformation>

Returns Task<TResult>.

OnAbort()

Executes the abort action.

protected override void OnAbort()

OnBeginClose(TimeSpan, AsyncCallback, object)

Executes the begin close action.

protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)

Parameters

timeout TimeSpan

The wait time before the operation times out.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains information about the receive operation. This object is passed to the EndClose delegate when the operation is complete.

Returns

IAsyncResult

An IAsyncResult that references the asynchronous Close operation.

OnBeginOpen(TimeSpan, AsyncCallback, object)

Executes the begin open action.

protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)

Parameters

timeout TimeSpan

The wait time before the operation times out.

callback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state object

A user-defined object that contains information about the receive operation. This object is passed to the EndOpen delegate when the operation is complete.

Returns

IAsyncResult

An IAsyncResult that references the asynchronous Open operation.

OnClose(TimeSpan)

Executes the close action.

protected override void OnClose(TimeSpan timeout)

Parameters

timeout TimeSpan

The wait time before the operation times out.

OnEndClose(IAsyncResult)

Executes the end close action.

protected override void OnEndClose(IAsyncResult result)

Parameters

result IAsyncResult

An IAsyncResult that references the asynchronous Close operation.

OnEndOpen(IAsyncResult)

Executes the end open action.

protected override void OnEndOpen(IAsyncResult result)

Parameters

result IAsyncResult

An IAsyncResult that references the asynchronous Open operation.

Send(EventData)

Sends event data to an Event Hub.

public void Send(EventData data)

Parameters

data EventData

The event data.

SendAsync(EventData)

Asynchronously sends event data to an Event Hub.

public Task SendAsync(EventData data)

Parameters

data EventData

The EventData to send.

Returns

Task

The task representing the asynchronous operation.

SendBatch(IEnumerable<EventData>)

Sends a batch of event data to the logical partition represented by PartitionId.

public void SendBatch(IEnumerable<EventData> eventDataList)

Parameters

eventDataList IEnumerable<EventData>

An System.Collections.Generic.IEnumerable object containing event data instances.

Exceptions

MessageSizeExceededException

Thrown if the total serialized size of eventDataList exceeds the allowed size limit for one event transmission (256k by default).

SendBatchAsync(IEnumerable<EventData>)

Asynchronously sends a batch of event data to the logical partition represented by PartitionId.

public Task SendBatchAsync(IEnumerable<EventData> eventDataList)

Parameters

eventDataList IEnumerable<EventData>

An System.Collections.Generic.IEnumerable object containing event data instances.

Returns

Task

Returns Task.

Exceptions

MessageSizeExceededException

Thrown if the total serialized size of eventDataList exceeds the allowed size limit for one event transmission (256k by default).