PartitionSender.SendAsync Method

Definition

Overloads

SendAsync(EventData)

Send EventData to a specific EventHub partition. The target partition is pre-determined when this PartitionSender was created. This send pattern emphasizes data correlation over general availability and latency.

There are 3 ways to send to EventHubs, each exposed as a method (along with its sendBatch overload):

i. SendAsync(EventData) or SendAsync(IEnumerable<EventData>)

ii. SendAsync(EventData, String) or SendAsync(IEnumerable<EventData>, String)

iii. SendAsync(EventData) or SendAsync(IEnumerable<EventData>)

Use this type of send if:

a. The client wants to take direct control of distribution of data across partitions. In this case client is responsible for making sure there is at least one sender per event hub partition.

b. User cannot use partition key as a mean to direct events to specific partition, yet there is a need for data correlation with partitioning scheme.

SendAsync(EventDataBatch)

Send a batch of EventData in EventDataBatch.

SendAsync(IEnumerable<EventData>)

Send EventData to a specific EventHub partition. The targeted partition is pre-determined when this PartitionSender was created.

There are 3 ways to send to EventHubs, to understand this particular type of send refer to the overload SendAsync(EventData), which is the same type of send and is used to send single EventData.

Sending a batch of EventData's is useful in the following cases:

i. Efficient send - sending a batch of EventData maximizes the overall throughput by optimally using the number of sessions created to EventHubs' service.

ii. Sending multiple EventData's in a Transaction. To acheive ACID properties, the Gateway Service will forward all EventData's in the batch to a single EventHub partition.

SendAsync(EventData)

Source:
PartitionSender.cs

Send EventData to a specific EventHub partition. The target partition is pre-determined when this PartitionSender was created. This send pattern emphasizes data correlation over general availability and latency.

There are 3 ways to send to EventHubs, each exposed as a method (along with its sendBatch overload):

i. SendAsync(EventData) or SendAsync(IEnumerable<EventData>)

ii. SendAsync(EventData, String) or SendAsync(IEnumerable<EventData>, String)

iii. SendAsync(EventData) or SendAsync(IEnumerable<EventData>)

Use this type of send if:

a. The client wants to take direct control of distribution of data across partitions. In this case client is responsible for making sure there is at least one sender per event hub partition.

b. User cannot use partition key as a mean to direct events to specific partition, yet there is a need for data correlation with partitioning scheme.

public System.Threading.Tasks.Task SendAsync (Microsoft.Azure.EventHubs.EventData eventData);
member this.SendAsync : Microsoft.Azure.EventHubs.EventData -> System.Threading.Tasks.Task
Public Function SendAsync (eventData As EventData) As Task

Parameters

eventData
EventData

the EventData to be sent.

Returns

A Task that completes when the send operations is done.

Exceptions

the total size of the EventData exceeds a pre-defined limit set by the service. Default is 256k bytes.

Event Hubs service encountered problems during the operation.

Applies to

SendAsync(EventDataBatch)

Source:
PartitionSender.cs

Send a batch of EventData in EventDataBatch.

public System.Threading.Tasks.Task SendAsync (Microsoft.Azure.EventHubs.EventDataBatch eventDataBatch);
member this.SendAsync : Microsoft.Azure.EventHubs.EventDataBatch -> System.Threading.Tasks.Task
Public Function SendAsync (eventDataBatch As EventDataBatch) As Task

Parameters

eventDataBatch
EventDataBatch

the batch of events to send to EventHub

Returns

A Task that completes when the send operation is done.

Applies to

SendAsync(IEnumerable<EventData>)

Source:
PartitionSender.cs

Send EventData to a specific EventHub partition. The targeted partition is pre-determined when this PartitionSender was created.

There are 3 ways to send to EventHubs, to understand this particular type of send refer to the overload SendAsync(EventData), which is the same type of send and is used to send single EventData.

Sending a batch of EventData's is useful in the following cases:

i. Efficient send - sending a batch of EventData maximizes the overall throughput by optimally using the number of sessions created to EventHubs' service.

ii. Sending multiple EventData's in a Transaction. To acheive ACID properties, the Gateway Service will forward all EventData's in the batch to a single EventHub partition.

public System.Threading.Tasks.Task SendAsync (System.Collections.Generic.IEnumerable<Microsoft.Azure.EventHubs.EventData> eventDatas);
member this.SendAsync : seq<Microsoft.Azure.EventHubs.EventData> -> System.Threading.Tasks.Task
Public Function SendAsync (eventDatas As IEnumerable(Of EventData)) As Task

Parameters

eventDatas
IEnumerable<EventData>

batch of events to send to EventHub

Returns

a Task that completes when the send operation is done.

Exceptions

the total size of the EventData exceeds a pre-defined limit set by the service. Default is 256k bytes.

Event Hubs service encountered problems during the operation.

Examples

Sample code:

EventHubClient client = EventHubClient.Create("__connectionString__");
PartitionSender senderToPartitionOne = client.CreatePartitionSender("1");

while (true)
{
    var events = new List<EventData>();
    for (int count = 1; count < 11; count++)
    {
        var payload = new PayloadEvent(count);
        byte[] payloadBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload));
        var sendEvent = new EventData(payloadBytes);
        var applicationProperties = new Dictionary<string, string>();
        applicationProperties["from"] = "csharpClient";
        sendEvent.Properties = applicationProperties;
        events.Add(sendEvent);
    }

    await senderToPartitionOne.SendAsync(events);
    Console.WriteLine("Sent Batch... Size: {0}", events.Count);

}

Applies to