Skip to content

Commit c036681

Browse files
authored
Merge pull request #109390 from spelluru/ehubdotnetmigrationguide0327
Fixed the link to the migration guide
2 parents 62f4fec + 9ba3003 commit c036681

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

articles/event-hubs/event-hubs-availability-and-consistency.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.devlang: na
1212
ms.topic: article
1313
ms.tgt_pltfrm: na
1414
ms.workload: na
15-
ms.date: 01/29/2020
15+
ms.date: 03/27/2020
1616
ms.author: shvija
1717

1818
---
@@ -33,12 +33,63 @@ Brewer's theorem defines consistency and availability as follows:
3333
Event Hubs is built on top of a partitioned data model. You can configure the number of partitions in your event hub during setup, but you cannot change this value later. Since you must use partitions with Event Hubs, you have to make a decision about availability and consistency for your application.
3434

3535
## Availability
36-
The simplest way to get started with Event Hubs is to use the default behavior. If you create a new **[EventHubClient](/dotnet/api/microsoft.azure.eventhubs.eventhubclient)** object and use the **[Send](/dotnet/api/microsoft.azure.eventhubs.eventhubclient.sendasync?view=azure-dotnet#Microsoft_Azure_EventHubs_EventHubClient_SendAsync_Microsoft_Azure_EventHubs_EventData_)** method, your events are automatically distributed between partitions in your event hub. This behavior allows for the greatest amount of up time.
36+
The simplest way to get started with Event Hubs is to use the default behavior.
37+
38+
#### [Azure.Messaging.EventHubs (5.0.0 or later)](#tab/latest)
39+
If you create a new **[EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient?view=azure-dotnet)** object and use the **[SendAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.sendasync?view=azure-dotnet)** method, your events are automatically distributed between partitions in your event hub. This behavior allows for the greatest amount of up time.
40+
41+
#### [Microsoft.Azure.EventHubs (4.1.0 or earlier)](#tab/old)
42+
If you create a new **[EventHubClient](/dotnet/api/microsoft.azure.eventhubs.eventhubclient)** object and use the **[Send](/dotnet/api/microsoft.azure.eventhubs.eventhubclient.sendasync?view=azure-dotnet#Microsoft_Azure_EventHubs_EventHubClient_SendAsync_Microsoft_Azure_EventHubs_EventData_)** method, your events are automatically distributed between partitions in your event hub. This behavior allows for the greatest amount of up time.
43+
44+
---
3745

3846
For use cases that require the maximum up time, this model is preferred.
3947

4048
## Consistency
41-
In some scenarios, the ordering of events can be important. For example, you may want your back-end system to process an update command before a delete command. In this instance, you can either set the partition key on an event, or use a `PartitionSender` object to only send events to a certain partition. Doing so ensures that when these events are read from the partition, they are read in order.
49+
In some scenarios, the ordering of events can be important. For example, you may want your back-end system to process an update command before a delete command. In this instance, you can either set the partition key on an event, or use a `PartitionSender` object (if you are using the old Microsoft.Azure.Messaging library) to only send events to a certain partition. Doing so ensures that when these events are read from the partition, they are read in order. If you are using the **Azure.Messaging.EventHubs** library and for more information, see [Migrating code from PartitionSender to EventHubProducerClient for publishing events to a partition](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/MigrationGuide.md#migrating-code-from-partitionsender-to-eventhubproducerclient-for-publishing-events-to-a-partition).
50+
51+
#### [Azure.Messaging.EventHubs (5.0.0 or later)](#tab/latest)
52+
53+
```csharp
54+
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
55+
var eventHubName = "<< NAME OF THE EVENT HUB >>";
56+
57+
await using (var producerClient = new EventHubProducerClient(connectionString, eventHubName))
58+
{
59+
var batchOptions = new CreateBatchOptions() { PartitionId = "my-partition-id" };
60+
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync(batchOptions);
61+
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("First")));
62+
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Second")));
63+
64+
await producerClient.SendAsync(eventBatch);
65+
}
66+
```
67+
68+
#### [Microsoft.Azure.EventHubs (4.1.0 or earlier)](#tab/old)
69+
70+
```csharp
71+
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
72+
var eventHubName = "<< NAME OF THE EVENT HUB >>";
73+
74+
var connectionStringBuilder = new EventHubsConnectionStringBuilder(connectionString){ EntityPath = eventHubName };
75+
var eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
76+
PartitionSender partitionSender = eventHubClient.CreatePartitionSender("my-partition-id");
77+
try
78+
{
79+
EventDataBatch eventBatch = partitionSender.CreateBatch();
80+
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("First")));
81+
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Second")));
82+
83+
await partitionSender.SendAsync(eventBatch);
84+
}
85+
finally
86+
{
87+
await partitionSender.CloseAsync();
88+
await eventHubClient.CloseAsync();
89+
}
90+
```
91+
92+
---
4293

4394
With this configuration, keep in mind that if the particular partition to which you are sending is unavailable, you will receive an error response. As a point of comparison, if you do not have an affinity to a single partition, the Event Hubs service sends your event to the next available partition.
4495

articles/event-hubs/event-hubs-dotnet-standard-getstarted-send.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ms.author: spelluru
2121
This quickstart shows how to send events to and receive events from an event hub using the **Microsoft.Azure.EventHubs** .NET Core library.
2222

2323
> [!WARNING]
24-
> This quickstart uses the old **Microsoft.Azure.EventHubs** package. For a quickstart that uses the latest **Azure.Messaging.EventHubs** library, see [Send and receive events using Azure.Messaging.EventHubs library](get-started-dotnet-standard-send-v2.md). To move your application from using the old library to new one, see the [Guide to migrate from Microsoft.Azure.EventHubs to Azure.Messaging.EventHubs](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/migration-guide-from-v4.md).
24+
> This quickstart uses the old **Microsoft.Azure.EventHubs** package. For a quickstart that uses the latest **Azure.Messaging.EventHubs** library, see [Send and receive events using Azure.Messaging.EventHubs library](get-started-dotnet-standard-send-v2.md). To move your application from using the old library to new one, see the [Guide to migrate from Microsoft.Azure.EventHubs to Azure.Messaging.EventHubs](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/MigrationGuide.md).
2525
2626
## Prerequisites
2727
If you are new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you do this quickstart.

0 commit comments

Comments
 (0)