Skip to content

Commit 2e936aa

Browse files
committed
switched the tabs back
1 parent df36e3c commit 2e936aa

File tree

2 files changed

+77
-71
lines changed

2 files changed

+77
-71
lines changed

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

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,47 @@ This section shows you how to create a .NET Core console application to send eve
4747

4848
### Add the NuGet packages to the project
4949

50-
### [Connection String](#tab/connection-string)
50+
51+
### [Passwordless (Recommended)](#tab/passwordless)
5152

5253
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
53-
1. Run the following command to install the **Azure.Messaging.EventHubs** NuGet package:
54+
1. Run the following commands to install **Azure.Messaging.EventHubs** and **Azure.Identity** NuGet packages. Press **ENTER** to run the second command.
5455

5556
```powershell
5657
Install-Package Azure.Messaging.EventHubs
58+
Install-Package Azure.Identity
5759
```
5860
59-
### [Passwordless (Recommended)](#tab/passwordless)
61+
### [Connection String](#tab/connection-string)
6062
6163
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
62-
1. Run the following commands to install **Azure.Messaging.EventHubs** and **Azure.Identity** NuGet packages. Press **ENTER** to run the second command.
64+
1. Run the following command to install the **Azure.Messaging.EventHubs** NuGet package:
6365
6466
```powershell
6567
Install-Package Azure.Messaging.EventHubs
66-
Install-Package Azure.Identity
6768
```
6869
69-
7070
---
7171
7272
7373
### Write code to send events to the event hub
7474
75-
## [Connection String](#tab/connection-string)
7675
77-
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<CONNECTION_STRING>` and `<HUB_NAME>` placeholder values for the `EventHubProducerClient` parameters.
76+
## [Passwordless (Recommended)](#tab/passwordless)
77+
78+
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace `<EVENT_HUB_NAMESPACE>` and `<HUB_NAME>` placeholder values for the `EventHubProducerClient` parameters with the names of your Event Hubs namespace and the event hub. For example: `"spehubns0309.servicebus.windows.net"` and `"spehub"`.
7879
7980
Here are the important steps from the code:
8081
81-
1. Creates a [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object using the primary connection string to the namespace and the event hub name.
82-
1. Invokes the [CreateBatchAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.createbatchasync) method on the [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object to create a [EventDataBatch](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch) object.
82+
1. Creates an [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object using the namespace and the event hub name.
83+
1. Invokes the [CreateBatchAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.createbatchasync) method on the [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object to create an [EventDataBatch](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch) object.
8384
1. Add events to the batch using the [EventDataBatch.TryAdd](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch.tryadd) method.
8485
1. Sends the batch of messages to the event hub using the [EventHubProducerClient.SendAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.sendasync) method.
85-
86+
87+
8688
8789
```csharp
90+
using Azure.Identity;
8891
using Azure.Messaging.EventHubs;
8992
using Azure.Messaging.EventHubs.Producer;
9093
using System.Text;
@@ -94,10 +97,11 @@ This section shows you how to create a .NET Core console application to send eve
9497
9598
// The Event Hubs client types are safe to cache and use as a singleton for the lifetime
9699
// of the application, which is best practice when events are being published or read regularly.
97-
// TODO: Replace the <CONNECTION_STRING> and <HUB_NAME> placeholder values
100+
// TODO: Replace the <EVENT_HUB_NAMESPACE> and <HUB_NAME> placeholder values
98101
EventHubProducerClient producerClient = new EventHubProducerClient(
99-
"<CONNECTION_STRING>",
100-
"<HUB_NAME>");
102+
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
103+
"<HUB_NAME>",
104+
new DefaultAzureCredential());
101105
102106
// Create a batch of events
103107
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
@@ -124,21 +128,19 @@ This section shows you how to create a .NET Core console application to send eve
124128
}
125129
```
126130
127-
## [Passwordless (Recommended)](#tab/passwordless)
131+
## [Connection String](#tab/connection-string)
128132
129-
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace `<EVENT_HUB_NAMESPACE>` and `<HUB_NAME>` placeholder values for the `EventHubProducerClient` parameters with the names of your Event Hubs namespace and the event hub. For example: `"spehubns0309.servicebus.windows.net"` and `"spehub"`.
133+
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<CONNECTION_STRING>` and `<HUB_NAME>` placeholder values for the `EventHubProducerClient` parameters.
130134
131135
Here are the important steps from the code:
132136
133-
1. Creates an [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object using the namespace and the event hub name.
134-
1. Invokes the [CreateBatchAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.createbatchasync) method on the [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object to create an [EventDataBatch](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch) object.
137+
1. Creates a [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object using the primary connection string to the namespace and the event hub name.
138+
1. Invokes the [CreateBatchAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.createbatchasync) method on the [EventHubProducerClient](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) object to create a [EventDataBatch](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch) object.
135139
1. Add events to the batch using the [EventDataBatch.TryAdd](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch.tryadd) method.
136140
1. Sends the batch of messages to the event hub using the [EventHubProducerClient.SendAsync](/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient.sendasync) method.
137-
138-
141+
139142
140143
```csharp
141-
using Azure.Identity;
142144
using Azure.Messaging.EventHubs;
143145
using Azure.Messaging.EventHubs.Producer;
144146
using System.Text;
@@ -148,11 +150,10 @@ This section shows you how to create a .NET Core console application to send eve
148150
149151
// The Event Hubs client types are safe to cache and use as a singleton for the lifetime
150152
// of the application, which is best practice when events are being published or read regularly.
151-
// TODO: Replace the <EVENT_HUB_NAMESPACE> and <HUB_NAME> placeholder values
153+
// TODO: Replace the <CONNECTION_STRING> and <HUB_NAME> placeholder values
152154
EventHubProducerClient producerClient = new EventHubProducerClient(
153-
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
154-
"<HUB_NAME>",
155-
new DefaultAzureCredential());
155+
"<CONNECTION_STRING>",
156+
"<HUB_NAME>");
156157
157158
// Create a batch of events
158159
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
@@ -213,15 +214,16 @@ In this quickstart, you use Azure Storage as the checkpoint store. Follow these
213214
214215
[!INCLUDE [storage-checkpoint-store-recommendations](./includes/storage-checkpoint-store-recommendations.md)]
215216
217+
## [Passwordless (Recommended)](#tab/passwordless)
218+
219+
[!INCLUDE [event-hub-storage-assign-roles](../../includes/passwordless/event-hub/event-hub-storage-assign-roles.md)]
220+
216221
## [Connection String](#tab/connection-string)
217222
218223
[Get the connection string to the storage account](../storage/common/storage-account-get-info.md#get-a-connection-string-for-the-storage-account)
219224
220225
Note down the connection string and the container name. You use them in the code to receive events from the event hub.
221226
222-
## [Passwordless (Recommended)](#tab/passwordless)
223-
224-
[!INCLUDE [event-hub-storage-assign-roles](../../includes/passwordless/event-hub/event-hub-storage-assign-roles.md)]
225227
226228
---
227229
### Create a project for the receiver
@@ -233,63 +235,69 @@ Note down the connection string and the container name. You use them in the code
233235
234236
### Add the NuGet packages to the project
235237
236-
### [Connection String](#tab/connection-string)
238+
239+
### [Passwordless (Recommended)](#tab/passwordless)
237240
238241
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
239242
1. In the **Package Manager Console** window, confirm that **EventHubsReceiver** is selected for the **Default project**. If not, use the drop-down list to select **EventHubsReceiver**.
240-
1. Run the following command to install the **Azure.Messaging.EventHubs** NuGet package:
243+
1. Run the following command to install the **Azure.Messaging.EventHubs** and the **Azure.Identity** NuGet packages. Press **ENTER** to run the last command.
241244
242245
```powershell
243246
Install-Package Azure.Messaging.EventHubs
244247
Install-Package Azure.Messaging.EventHubs.Processor
248+
Install-Package Azure.Identity
245249
```
246250
247-
### [Passwordless (Recommended)](#tab/passwordless)
251+
### [Connection String](#tab/connection-string)
248252
249253
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
250254
1. In the **Package Manager Console** window, confirm that **EventHubsReceiver** is selected for the **Default project**. If not, use the drop-down list to select **EventHubsReceiver**.
251-
1. Run the following command to install the **Azure.Messaging.EventHubs** and the **Azure.Identity** NuGet packages. Press **ENTER** to run the last command.
255+
1. Run the following command to install the **Azure.Messaging.EventHubs** NuGet package:
252256
253257
```powershell
254258
Install-Package Azure.Messaging.EventHubs
255259
Install-Package Azure.Messaging.EventHubs.Processor
256-
Install-Package Azure.Identity
257260
```
258261
259262
---
260263
### Update the code
261264
262265
Replace the contents of **Program.cs** with the following code:
263266
264-
## [Connection String](#tab/connection-string)
267+
## [Passwordless (Recommended)](#tab/passwordless)
265268
266-
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<AZURE_STORAGE_CONNECTION_STRING>` and `<BLOB_CONTAINER_NAME>` placeholder values for the `BlobContainerClient` URI. Replace the `<EVENT_HUB_NAMESPACE_CONNECTION_STRING>` and `<HUB_NAME>` placeholder values for the `EventProcessorClient` as well.
269+
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<STORAGE_ACCOUNT_NAME>` and `<BLOB_CONTAINER_NAME>` placeholder values for the `BlobContainerClient` URI. Replace the `<EVENT_HUB_NAMESPACE>` and `<HUB_NAME>` placeholder values for the `EventProcessorClient` as well.
267270
268271
Here are the important steps from the code:
269272
270-
1. Creates an [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object using the primary connection string to the namespace and the event hub. You need to build [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object for the container in the Azure storage you created earlier.
273+
1. Creates an [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object using the Event Hubs namespace and the event hub name. You need to build [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object for the container in the Azure storage you created earlier.
271274
1. Specifies handlers for the [ProcessEventAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.processeventasync) and [ProcessErrorAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.processerrorasync) events of the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
272275
1. Starts processing events by invoking the [StartProcessingAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.startprocessingasync) on the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
273276
1. Stops processing events after 30 seconds by invoking [StopProcessingAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.stopprocessingasync) on the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
274277
275-
278+
276279
```csharp
280+
using Azure.Identity;
277281
using Azure.Messaging.EventHubs;
278282
using Azure.Messaging.EventHubs.Consumer;
279283
using Azure.Messaging.EventHubs.Processor;
280284
using Azure.Storage.Blobs;
281285
using System.Text;
282286
283-
// Create a blob container client that the event processor will use
287+
// Create a blob container client that the event processor will use
288+
// TODO: Replace <STORAGE_ACCOUNT_NAME> and <BLOB_CONTAINER_NAME> with actual names
284289
BlobContainerClient storageClient = new BlobContainerClient(
285-
"<AZURE_STORAGE_CONNECTION_STRING>", "<BLOB_CONTAINER_NAME>");
290+
new Uri("https://<STORAGE_ACCOUNT_NAME>.blob.core.windows.net/<BLOB_CONTAINER_NAME>"),
291+
new DefaultAzureCredential());
286292
287293
// Create an event processor client to process events in the event hub
294+
// TODO: Replace the <EVENT_HUBS_NAMESPACE> and <HUB_NAME> placeholder values
288295
var processor = new EventProcessorClient(
289296
storageClient,
290297
EventHubConsumerClient.DefaultConsumerGroupName,
291-
"<EVENT_HUBS_NAMESPACE_CONNECTION_STRING>",
292-
"<HUB_NAME>");
298+
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
299+
"<HUB_NAME>",
300+
new DefaultAzureCredential());
293301
294302
// Register handlers for processing events and handling errors
295303
processor.ProcessEventAsync += ProcessEventHandler;
@@ -308,6 +316,7 @@ Replace the contents of **Program.cs** with the following code:
308316
{
309317
// Write the body of the event to the console window
310318
Console.WriteLine("\tReceived event: {0}", Encoding.UTF8.GetString(eventArgs.Data.Body.ToArray()));
319+
Console.ReadLine();
311320
return Task.CompletedTask;
312321
}
313322
@@ -316,44 +325,40 @@ Replace the contents of **Program.cs** with the following code:
316325
// Write details about the error to the console window
317326
Console.WriteLine($"\tPartition '{eventArgs.PartitionId}': an unhandled exception was encountered. This was not expected to happen.");
318327
Console.WriteLine(eventArgs.Exception.Message);
328+
Console.ReadLine();
319329
return Task.CompletedTask;
320330
}
321331
```
322332
323-
## [Passwordless (Recommended)](#tab/passwordless)
333+
## [Connection String](#tab/connection-string)
324334
325-
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<STORAGE_ACCOUNT_NAME>` and `<BLOB_CONTAINER_NAME>` placeholder values for the `BlobContainerClient` URI. Replace the `<EVENT_HUB_NAMESPACE>` and `<HUB_NAME>` placeholder values for the `EventProcessorClient` as well.
335+
1. Replace the existing code in the `Program.cs` file with the following sample code. Then, replace the `<AZURE_STORAGE_CONNECTION_STRING>` and `<BLOB_CONTAINER_NAME>` placeholder values for the `BlobContainerClient` URI. Replace the `<EVENT_HUB_NAMESPACE_CONNECTION_STRING>` and `<HUB_NAME>` placeholder values for the `EventProcessorClient` as well.
326336
327337
Here are the important steps from the code:
328338
329-
1. Creates an [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object using the Event Hubs namespace and the event hub name. You need to build [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object for the container in the Azure storage you created earlier.
339+
1. Creates an [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object using the primary connection string to the namespace and the event hub. You need to build [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object for the container in the Azure storage you created earlier.
330340
1. Specifies handlers for the [ProcessEventAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.processeventasync) and [ProcessErrorAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.processerrorasync) events of the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
331341
1. Starts processing events by invoking the [StartProcessingAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.startprocessingasync) on the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
332342
1. Stops processing events after 30 seconds by invoking [StopProcessingAsync](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient.stopprocessingasync) on the [EventProcessorClient](/dotnet/api/azure.messaging.eventhubs.eventprocessorclient) object.
333343
334-
344+
335345
```csharp
336-
using Azure.Identity;
337346
using Azure.Messaging.EventHubs;
338347
using Azure.Messaging.EventHubs.Consumer;
339348
using Azure.Messaging.EventHubs.Processor;
340349
using Azure.Storage.Blobs;
341350
using System.Text;
342351
343-
// Create a blob container client that the event processor will use
344-
// TODO: Replace <STORAGE_ACCOUNT_NAME> and <BLOB_CONTAINER_NAME> with actual names
352+
// Create a blob container client that the event processor will use
345353
BlobContainerClient storageClient = new BlobContainerClient(
346-
new Uri("https://<STORAGE_ACCOUNT_NAME>.blob.core.windows.net/<BLOB_CONTAINER_NAME>"),
347-
new DefaultAzureCredential());
354+
"<AZURE_STORAGE_CONNECTION_STRING>", "<BLOB_CONTAINER_NAME>");
348355
349356
// Create an event processor client to process events in the event hub
350-
// TODO: Replace the <EVENT_HUBS_NAMESPACE> and <HUB_NAME> placeholder values
351357
var processor = new EventProcessorClient(
352358
storageClient,
353359
EventHubConsumerClient.DefaultConsumerGroupName,
354-
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
355-
"<HUB_NAME>",
356-
new DefaultAzureCredential());
360+
"<EVENT_HUBS_NAMESPACE_CONNECTION_STRING>",
361+
"<HUB_NAME>");
357362
358363
// Register handlers for processing events and handling errors
359364
processor.ProcessEventAsync += ProcessEventHandler;
@@ -372,7 +377,6 @@ Replace the contents of **Program.cs** with the following code:
372377
{
373378
// Write the body of the event to the console window
374379
Console.WriteLine("\tReceived event: {0}", Encoding.UTF8.GetString(eventArgs.Data.Body.ToArray()));
375-
Console.ReadLine();
376380
return Task.CompletedTask;
377381
}
378382
@@ -381,11 +385,11 @@ Replace the contents of **Program.cs** with the following code:
381385
// Write details about the error to the console window
382386
Console.WriteLine($"\tPartition '{eventArgs.PartitionId}': an unhandled exception was encountered. This was not expected to happen.");
383387
Console.WriteLine(eventArgs.Exception.Message);
384-
Console.ReadLine();
385388
return Task.CompletedTask;
386389
}
387390
```
388391
392+
389393
390394
---
391395

0 commit comments

Comments
 (0)