1.3 KiB
1.3 KiB
uid: com.microsoft.azure.eventhubs._partition_receiver.receive(final int)
summary: Receives a batch of EventData objects from an Event Hubs partition.
remarks: *content
The following sample code uses the synchronous version of the API, but the concepts are the same:
EventHubClient client = createFromConnectionStringSync(final String connectionString)("connection");
PartitionReceiver receiver = client.createPartitionReceiverSync("ConsumerGroup1", "1");
Iterable{<}EventData{>} receivedEvents = receiver.receiveSync();
while (true)
{
int batchSize = 0;
if (receivedEvents != null)
{
for(EventData receivedEvent: receivedEvents)
{
System.out.println(String.format("Message Payload: %s", new String(receivedEvent.getBytes(), Charset.defaultCharset())));
System.out.println(String.format("Offset: %s, SeqNo: %s, EnqueueTime: %s", receivedEvent.getSystemProperties().getOffset(), receivedEvent.getSystemProperties().getSequenceNumber(), receivedEvent.getSystemProperties().getEnqueuedTime()));
batchSize++;
}
}
System.out.println(String.format("ReceivedBatch Size: %s", batchSize));
receivedEvents = receiver.receiveSync();
}