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
The focus of these changes is to tweak the content and format of the Event
Hubs README snippets to clarify lifetime guidance explicitly in each example
and to add an illustration of registering with ASP.NET Core DI. Tweaked the
layout of the Service Bus examples, moving the ASP.NET Core section to an
example to streamline the "Authenticating the client" section and focus on
the core "Getting Started" scenario.
Copy file name to clipboardExpand all lines: sdk/eventhub/Azure.Messaging.EventHubs.Processor/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,8 @@ For the Event Hubs client library to interact with an Event Hub, it will need to
54
54
55
55
For the event processor client to make use of Azure Storage blobs for checkpointing, it will need to understand how to connect to a storage account and authorize with it. The most straightforward method of doing so is to use a connection string, which is generated at the time that the storage account is created. If you aren't familiar with storage account connection string authorization in Azure, you may wish to follow the step-by-step guide to [configure Azure Storage connection strings](https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string).
56
56
57
+
Once you have the connection strings, see [Creating an Event Processor Client](#creating-an-event-processor-client) for an example of how to use them to create the processor.
58
+
57
59
## Key concepts
58
60
59
61
- An **event processor** is a construct intended to manage the responsibilities associated with connecting to a given Event Hub and processing events from each of its partitions, in the context of a specific consumer group. The act of processing events read from the partition and handling any errors that occur is delegated by the event processor to code that you provide, allowing your logic to concentrate on delivering business value while the processor handles the tasks associated with reading events, managing the partitions, and allowing state to be persisted in the form of checkpoints.
For the Event Hubs client library to interact with an Event Hub, it will need to understand how to connect and authorize with it. The easiest means for doing so is to use a connection string, which is created automatically when creating an Event Hubs namespace. If you aren't familiar with using connection strings with Event Hubs, you may wish to follow the step-by-step guide to [get an Event Hubs connection string](https://docs.microsoft.com/azure/event-hubs/event-hubs-get-connection-string).
47
+
48
+
Once you have a connection string, any of the Event Hubs client types can be created with it:
For examples of authenticating the Event Hubs clients with credential types, see [Using an Azure Active Directory (AAD) principal](#using-an-active-directory-principal-with-the-event-hub-clients) or the [Identity and Shared Access Credentials](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Azure.Messaging.EventHubs/samples/Sample06_IdentityAndSharedAccessCredentials.md) sample.
62
+
63
+
For examples of authenticating the Event Hubs clients for an ASP.NET Core application, see [Registering with ASP.NET Core dependency injection](#registering-with-aspnet-core-dependency-injection).
64
+
47
65
## Key concepts
48
66
49
67
- An **Event Hub client** is the primary interface for developers interacting with the Event Hubs client library. There are several different Event Hub clients, each dedicated to a specific use of Event Hubs, such as publishing or consuming events.
@@ -85,6 +103,10 @@ Many Event Hub operations take place within the scope of a specific partition.
85
103
varconnectionString="<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
86
104
vareventHubName="<< NAME OF THE EVENT HUB >>";
87
105
106
+
// It is recommended that you cache the Event Hubs clients for the lifetime of your
107
+
// application, closing or disposing when application ends. This example disposes
@@ -221,7 +259,7 @@ More details can be found in the Event Processor Client [README](https://github.
221
259
222
260
### Using an Active Directory principal with the Event Hub clients
223
261
224
-
The [Azure Identity library](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md) provides Azure Active Directory authentication support which can be used for the Azure client libraries, including Event Hubs.
262
+
The [Azure Identity library](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md) provides Azure Active Directory (AAD) authentication support which can be used for the Azure client libraries, including Event Hubs.
225
263
226
264
To make use of an Active Directory principal, one of the available credentials from the `Azure.Identity` library is specified when creating the Event Hubs client. In addition, the fully qualified Event Hubs namespace and the name of desired Event Hub are supplied in lieu of the Event Hubs connection string. For illustration, the `EventHubProducerClient` is demonstrated in these examples, but the concept and form are common across clients.
227
265
@@ -230,18 +268,82 @@ var fullyQualifiedNamespace = "<< FULLY-QUALIFIED EVENT HUBS NAMESPACE (like som
230
268
vareventHubName="<< NAME OF THE EVENT HUB >>";
231
269
varcredential=newDefaultAzureCredential();
232
270
271
+
// It is recommended that you cache the Event Hubs clients for the lifetime of your
272
+
// application, closing or disposing when application ends. This example disposes
if ((!eventBatch.TryAdd(newEventData("First"))) ||
280
+
(!eventBatch.TryAdd(newEventData("Second"))))
281
+
{
282
+
thrownewApplicationException("Not all events could be added to the batch!");
283
+
}
238
284
239
285
awaitproducer.SendAsync(eventBatch);
240
286
}
241
287
```
242
288
243
289
When using Azure Active Directory, your principal must be assigned a role which allows access to Event Hubs, such as the `Azure Event Hubs Data Owner` role. For more information about using Azure Active Directory authorization with Event Hubs, please refer to [the associated documentation](https://docs.microsoft.com/azure/event-hubs/authorize-access-azure-active-directory).
244
290
291
+
### Registering with ASP.NET Core dependency injection
292
+
293
+
To inject one of the Event Hubs clients as a dependency in an ASP.NET Core application, install the Azure client library integration for ASP.NET Core package.
294
+
295
+
```dotnetcli
296
+
dotnet add package Microsoft.Extensions.Azure
297
+
```
298
+
299
+
After installing, register the desired Event Hubs client types in the `Startup.ConfigureServices` method:
For more details, see [Dependency injection with the Azure SDK for .NET](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection).
346
+
245
347
## Troubleshooting
246
348
247
349
For detailed troubleshooting information, please refer to the [Event Hubs Troubleshooting Guide](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/eventhub/Azure.Messaging.EventHubs/TROUBLESHOOTING.md).
0 commit comments