Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] Sample updates for the Buffered Producer #25388

Merged
merged 9 commits into from
Nov 18, 2021
15 changes: 6 additions & 9 deletions sdk/eventhub/Azure.Messaging.EventHubs/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,11 @@ var producer = new EventHubProducerClient(connectionString, eventHubName);

try
{
using var eventBatch = await producer.CreateBatchAsync();
using EventDataBatch eventBatch = await producer.CreateBatchAsync();

for (var index = 0; index < 5; ++index)
{
var eventBody = new BinaryData($"Event #{ index }");
var eventData = new EventData(eventBody);
var eventData = new EventData($"Event #{ index }");

if (!eventBatch.TryAdd(eventData))
{
Expand Down Expand Up @@ -286,12 +285,11 @@ try
PartitionKey = "Any Value Will Do..."
};

using var eventBatch = await producer.CreateBatchAsync(batchOptions);
using EventDataBatch eventBatch = await producer.CreateBatchAsync(batchOptions);

for (var index = 0; index < 5; ++index)
{
var eventBody = new BinaryData($"Event #{ index }");
var eventData = new EventData(eventBody);
var eventData = new EventData($"Event #{ index }");

if (!eventBatch.TryAdd(eventData))
{
Expand Down Expand Up @@ -364,12 +362,11 @@ try
PartitionId = firstPartition
};

using var eventBatch = await producer.CreateBatchAsync(batchOptions);
using EventDataBatch eventBatch = await producer.CreateBatchAsync(batchOptions);

for (var index = 0; index < 5; ++index)
{
var eventBody = new BinaryData($"Event #{ index }");
var eventData = new EventData(eventBody);
var eventData = new EventData($"Event #{ index }");

if (!eventBatch.TryAdd(eventData))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ The mainstream set of clients provides an approachable onboarding experience for

**Mainstream**

- The [EventHubProducerClient](https://docs.microsoft.com/dotnet/api/azure.messaging.eventhubs.producer?view=azure-dotnet) is responsible for publishing events and supports multiple approaches for selecting the partition to which the event is associated, including automatic routing by the Event Hubs service and specifying an explicit partition.
- The [EventHubBufferedProducerClient](https://docs.microsoft.com/dotnet/api/azure.messaging.eventhubs.producer?view=azure-dotnet) publishes events using a deferred model where events are collected into a buffer and the producer has responsibility for implicitly batching and sending them. More on the design and philosophy behind this type can be found in its [design document](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Azure.Messaging.EventHubs/design/proposal-event-hub-buffered-producer.md).

- The [EventHubProducerClient](https://docs.microsoft.com/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient?view=azure-dotnet) publishes events with explicit model where callers have responsibility for management of batches and controlling when events are sent.

- The [EventHubConsumerClient](https://docs.microsoft.com/dotnet/api/azure.messaging.eventhubs.consumer.eventhubconsumerclient?view=azure-dotnet) supports reading events from a single partition and also offers an easy way to familiarize yourself with Event Hubs by reading from all partitions without the rigor and complexity that you would need in a production application. For reading events from all partitions in a production scenario, we strongly recommend using the [EventProcessorClient](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/eventhub/Azure.Messaging.EventHubs.Processor/samples) from the [Azure.Messaging.EventHubs.Processor](https://www.nuget.org/packages/Azure.Messaging.EventHubs.Processor) package over the `EventHubConsumerClient`.

Expand Down
Loading