You are developing a C# application using the .NET SDK Azure.Messaging.EventHubs to send telemetry data to an Azure Event Hub. You need to write the code to send a batch of events efficiently and reliably. Which two actions must you perform to create and publish the event batch using the SDK? (Select TWO).
- Create an EventDataBatch object by calling CreateBatchAsync on the EventHubProducerClient instance.Cevap
- Add events to the batch using the TryAdd method, and then transmit the batch by calling SendAsync.Cevap
- CCall the AcquireLeaseAsync method on a BlobClient before sending the batch to prevent concurrent write conflicts on the Event Hub partitions.
- DInitialize the EventHubProducerClient specifically with a system-assigned managed identity, as user-assigned managed identities are not supported for the Azure Event Hubs Data Sender role.
Cevap
To publish a batch of events to an Azure Event Hub using the modern .NET SDK, you must create an EventDataBatch instance by calling CreateBatchAsync on the EventHubProducerClient, append events to it using the TryAdd method to ensure they do not exceed size constraints, and then send the completed batch using SendAsync.
Publishing events in batches using the .NET SDK requires calling CreateBatchAsync on an EventHubProducerClient to manage the size constraints. Individual events are added via TryAdd, and the completed batch is sent to the Event Hub using SendAsync.
Adım Adım Çözüm
Anahtar Kavram
Batch publishing pattern with EventHubProducerClient in the Azure.Messaging.EventHubs SDK