/
How-To read events from an Event Hub
How-To read events from an Event Hub
In order to read events from an Event Hub, you'll need to create an EventHubConsumerClient
for a given consumer group. When an Event Hub is created, it provides a default consumer group that can be used to get started with exploring Event Hubs : azure-sdk-for-net/README.md at main · Azure/azure-sdk-for-net · GitHub
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
var eventHubName = "<< NAME OF THE EVENT HUB >>";
string consumerGroup = EventHubConsumerClient.DefaultConsumerGroupName;
await using (var consumer = new EventHubConsumerClient(consumerGroup,
connectionString, eventHubName))
{
using var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(TimeSpan.FromSeconds(45));
await foreach (PartitionEvent receivedEvent in
consumer.ReadEventsAsync(cancellationSource.Token))
{
// At this point, the loop will wait for events to be available in the Event Hub.
// When an event
// is available, the loop will iterate with the event that was received.
// Because we did not
// specify a maximum wait time, the loop will wait forever unless cancellation
// is requested using the cancellation token.
}
}
, multiple selections available,
Related content
How-To read events from an Event Hub partition
How-To read events from an Event Hub partition
More like this
How-To publish events to an Event Hub
How-To publish events to an Event Hub
More like this
How-To use an Active Directory with the Event Hub Clients
How-To use an Active Directory with the Event Hub Clients
More like this
How-To inspect an Event Hub
How-To inspect an Event Hub
More like this
How-To process events using an Event Processor Client
How-To process events using an Event Processor Client
More like this
Understanding Event Consumers
Understanding Event Consumers
More like this