Share via


PartitionReceiver.ReceiveAsync Method

Definition

Overloads

ReceiveAsync(Int32)

Receive a batch of EventData's from an EventHub partition

ReceiveAsync(Int32, TimeSpan)

Receive a batch of EventData's from an EventHub partition by allowing wait time on each individual call.

ReceiveAsync(Int32)

Source:
PartitionReceiver.cs

Receive a batch of EventData's from an EventHub partition

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

Parameters

maxMessageCount
Int32

Returns

A Task that will yield a batch of EventData from the partition on which this receiver is created. Returns 'null' if no EventData is present.

Examples

Sample code:

EventHubClient client = EventHubClient.Create("__connectionString__");
PartitionReceiver receiver = client.CreateReceiver("ConsumerGroup1", "1");
IEnumerable<EventData> receivedEvents = await receiver.ReceiveAsync(BatchSize);

while (true)
{
    int batchSize = 0;
    if (receivedEvents != null)
    {
        foreach (EventData receivedEvent in receivedEvents)
        {
            Console.WriteLine("Message Payload: {0}", Encoding.UTF8.GetString(receivedEvent.Body));
            Console.WriteLine("Offset: {0}, SeqNo: {1}, EnqueueTime: {2}", 
                receivedEvent.SystemProperties.Offset, 
                receivedEvent.SystemProperties.SequenceNumber, 
                receivedEvent.SystemProperties.EnqueuedTime);
            batchSize++;
        }
    }

    Console.WriteLine("ReceivedBatch Size: {0}", batchSize);
    receivedEvents = await receiver.ReceiveAsync();
}

Applies to

ReceiveAsync(Int32, TimeSpan)

Source:
PartitionReceiver.cs

Receive a batch of EventData's from an EventHub partition by allowing wait time on each individual call.

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.Azure.EventHubs.EventData>> ReceiveAsync (int maxMessageCount, TimeSpan waitTime);
member this.ReceiveAsync : int * TimeSpan -> System.Threading.Tasks.Task<seq<Microsoft.Azure.EventHubs.EventData>>
Public Function ReceiveAsync (maxMessageCount As Integer, waitTime As TimeSpan) As Task(Of IEnumerable(Of EventData))

Parameters

maxMessageCount
Int32
waitTime
TimeSpan

Returns

A Task that will yield a batch of EventData from the partition on which this receiver is created. Returns 'null' if no EventData is present.

Applies to