You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
63
65
64
66
```powershell
65
67
Install-Package Azure.Messaging.EventHubs
66
-
Install-Package Azure.Identity
67
68
```
68
69
69
-
70
70
---
71
71
72
72
73
73
### Write code to send events to the event hub
74
74
75
-
## [Connection String](#tab/connection-string)
76
75
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.
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"`.
78
79
79
80
Here are the important steps from the code:
80
81
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.
83
84
1. Add events to the batch using the [EventDataBatch.TryAdd](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch.tryadd) method.
84
85
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
+
86
88
87
89
```csharp
90
+
using Azure.Identity;
88
91
using Azure.Messaging.EventHubs;
89
92
using Azure.Messaging.EventHubs.Producer;
90
93
using System.Text;
@@ -94,10 +97,11 @@ This section shows you how to create a .NET Core console application to send eve
94
97
95
98
// The Event Hubs client types are safe to cache and use as a singleton for the lifetime
96
99
// 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
98
101
EventHubProducerClient producerClient = new EventHubProducerClient(
99
-
"<CONNECTION_STRING>",
100
-
"<HUB_NAME>");
102
+
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
103
+
"<HUB_NAME>",
104
+
new DefaultAzureCredential());
101
105
102
106
// Create a batch of events
103
107
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
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.
130
134
131
135
Here are the important steps from the code:
132
136
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.
135
139
1. Add events to the batch using the [EventDataBatch.TryAdd](/dotnet/api/azure.messaging.eventhubs.producer.eventdatabatch.tryadd) method.
136
140
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
+
139
142
140
143
```csharp
141
-
using Azure.Identity;
142
144
using Azure.Messaging.EventHubs;
143
145
using Azure.Messaging.EventHubs.Producer;
144
146
using System.Text;
@@ -148,11 +150,10 @@ This section shows you how to create a .NET Core console application to send eve
148
150
149
151
// The Event Hubs client types are safe to cache and use as a singleton for the lifetime
150
152
// 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
152
154
EventHubProducerClient producerClient = new EventHubProducerClient(
153
-
"<EVENT_HUB_NAMESPACE>.servicebus.windows.net",
154
-
"<HUB_NAME>",
155
-
new DefaultAzureCredential());
155
+
"<CONNECTION_STRING>",
156
+
"<HUB_NAME>");
156
157
157
158
// Create a batch of events
158
159
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
@@ -213,15 +214,16 @@ In this quickstart, you use Azure Storage as the checkpoint store. Follow these
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
239
242
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.
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
250
254
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:
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.
267
270
268
271
Here are the important steps from the code:
269
272
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.
271
274
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.
272
275
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.
273
276
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.
274
277
275
-
278
+
276
279
```csharp
280
+
using Azure.Identity;
277
281
using Azure.Messaging.EventHubs;
278
282
using Azure.Messaging.EventHubs.Consumer;
279
283
using Azure.Messaging.EventHubs.Processor;
280
284
using Azure.Storage.Blobs;
281
285
using System.Text;
282
286
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
284
289
BlobContainerClient storageClient = new BlobContainerClient(
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.
326
336
327
337
Here are the important steps from the code:
328
338
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.
330
340
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.
331
341
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.
332
342
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.
333
343
334
-
344
+
335
345
```csharp
336
-
using Azure.Identity;
337
346
using Azure.Messaging.EventHubs;
338
347
using Azure.Messaging.EventHubs.Consumer;
339
348
using Azure.Messaging.EventHubs.Processor;
340
349
using Azure.Storage.Blobs;
341
350
using System.Text;
342
351
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
345
353
BlobContainerClient storageClient = new BlobContainerClient(
346
-
new Uri("https://<STORAGE_ACCOUNT_NAME>.blob.core.windows.net/<BLOB_CONTAINER_NAME>"),
0 commit comments