Skip to content

Commit

Permalink
[Event Hubs] Sample updates for the Buffered Producer (#25388)
Browse files Browse the repository at this point in the history
* [Event Hubs] Sample updates for the Buffered Producer

The focus of these changes is to incorporate the `EventHubBufferedProducer`
client into the Event Hubs samples for client types and publishing.  Also
included is a clarification for the logging sample, calling out the lifetime
needs for the listener.
  • Loading branch information
jsquire authored Nov 18, 2021
1 parent 9b94dfc commit f7f1aa1
Show file tree
Hide file tree
Showing 6 changed files with 607 additions and 100 deletions.
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

0 comments on commit f7f1aa1

Please sign in to comment.