Skip to content

Commit 99ea83b

Browse files
authored
Merge pull request #296906 from spelluru/freshness0321
.NET Quickstart
2 parents 3592173 + 35f2174 commit 99ea83b

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Quickstart: Send or receive events using .NET'
33
description: A quickstart that shows you how to create a .NET Core application that sends events to and receive events from Azure Event Hubs.
44
ms.topic: quickstart
5-
ms.date: 04/05/2024
5+
ms.date: 03/24/2025
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp, mode-api, passwordless-dotnet, devx-track-dotnet
88
#customer intent: As a .NET developer, I want to learn how to send events to an event hub and receive events from the event hub using C#.
@@ -12,15 +12,15 @@ ms.custom: devx-track-csharp, mode-api, passwordless-dotnet, devx-track-dotnet
1212
In this quickstart, you learn how to send events to an event hub and then receive those events from the event hub using the **Azure.Messaging.EventHubs** .NET library.
1313

1414
> [!NOTE]
15-
> Quickstarts are for you to quickly ramp up on the service. If you are already familiar with the service, you might want to see .NET samples for Event Hubs in our .NET SDK repository on GitHub: [Event Hubs samples on GitHub](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventhub/Azure.Messaging.EventHubs/samples), [Event processor samples on GitHub](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventhub/Azure.Messaging.EventHubs.Processor/samples).
15+
> Quickstarts are for you to quickly ramp up on the service. If you're already familiar with the service, you might want to see .NET samples for Event Hubs in our .NET SDK repository on GitHub: [Event Hubs samples on GitHub](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventhub/Azure.Messaging.EventHubs/samples), [Event processor samples on GitHub](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventhub/Azure.Messaging.EventHubs.Processor/samples).
1616
1717
## Prerequisites
1818
If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you go through this quickstart.
1919

2020
To complete this quickstart, you need the following prerequisites:
2121

22-
- **Microsoft Azure subscription**. To use Azure services, including Azure Event Hubs, you need a subscription. If you don't have an existing Azure account, you can sign up for a [free trial](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) or use your MSDN subscriber benefits when you [create an account](https://azure.microsoft.com).
23-
- **Microsoft Visual Studio 2022**. The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. You can still use the library with previous C# language versions, but the new syntax isn't available. To make use of the full syntax, we recommend that you compile with the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher and [language version](/dotnet/csharp/language-reference/configure-language-version#override-a-default) set to `latest`. If you're using Visual Studio, versions before Visual Studio 2022 aren't compatible with the tools needed to build C# 8.0 projects. Visual Studio 2022, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com/vs/).
22+
- **Microsoft Azure subscription**. To use Azure services, including Azure Event Hubs, you need a subscription. If you don't have an existing Azure account, you can sign up for a [free trial](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
23+
- **Microsoft Visual Studio 2022**. The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. You can still use the library with previous C# language versions, but the new syntax isn't available. To make use of the full syntax, we recommend that you compile with the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher and [language version](/dotnet/csharp/language-reference/configure-language-version#override-a-default) set to `latest`. If you're using Visual Studio, versions before Visual Studio 2022 aren't compatible with the tools needed to build C# 8.0 projects. Visual Studio 2022, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com/vs/).
2424
- **Create an Event Hubs namespace and an event hub**. The first step is to use the Azure portal to create an Event Hubs namespace and an event hub in the namespace. Then, obtain the management credentials that your application needs to communicate with the event hub. To create a namespace and an event hub, see [Quickstart: Create an event hub using Azure portal](event-hubs-create.md).
2525

2626
### Authenticate the app to Azure
@@ -47,6 +47,7 @@ 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+
5051
### [Passwordless (Recommended)](#tab/passwordless)
5152

5253
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
@@ -71,6 +72,7 @@ This section shows you how to create a .NET Core console application to send eve
7172
7273
### Write code to send events to the event hub
7374
75+
7476
## [Passwordless (Recommended)](#tab/passwordless)
7577
7678
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"`.
@@ -177,6 +179,8 @@ This section shows you how to create a .NET Core console application to send eve
177179
await producerClient.DisposeAsync();
178180
}
179181
```
182+
183+
180184
---
181185
182186
2. Build the project, and ensure that there are no errors.
@@ -186,12 +190,12 @@ This section shows you how to create a .NET Core console application to send eve
186190
A batch of 3 events has been published.
187191
```
188192
> [!NOTE]
189-
> If you get an error "InvalidIssuer: Token issuer is invalid" when using Microsoft Entra authentication, it may be because the wrong Entra Tenant Id is being used. In you code replace'new DefaultAzureCredential()' with 'new DefaultAzureCredential(new DefaultAzureCredentialOptions {TenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"})' to explicitly specify Entra Tenant Id.
193+
> If you get an error "InvalidIssuer: Token issuer is invalid" when using Microsoft Entra authentication, it might be because the wrong Microsoft Entra Tenant ID is being used. In your code, replace 'new DefaultAzureCredential()' with 'new DefaultAzureCredential(new DefaultAzureCredentialOptions {TenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"})' to explicitly specify Microsoft Entra Tenant ID.
190194
191195
192196
> [!IMPORTANT]
193-
> If you are using the Passwordless (Azure Active Directory's Role-based Access Control) authentication, select **Tools**, then select **Options**. In the **Options** window, expand **Azure Service Authentication**, and select **Account Selection**. Confirm that you are using the account that was added to the **Azure Event Hubs Data Owner** role on the Event Hubs namespace.
194-
4. On the **Event Hubs Namespace** page in the Azure portal, you see three incoming messages in the **Messages** chart. Refresh the page to update the chart if needed. It might take a few seconds for it to show that the messages have been received.
197+
> If you're using the Passwordless (Microsoft Entra's Role-based Access Control) authentication, select **Tools**, then select **Options**. In the **Options** window, expand **Azure Service Authentication**, and select **Account Selection**. Confirm that you're using the account that was added to the **Azure Event Hubs Data Owner** role on the Event Hubs namespace.
198+
4. On the **Event Hubs namespace** page in the Azure portal, you see three incoming messages in the **Messages** chart. Refresh the page to update the chart if needed. It might take a few seconds for it to show that the messages have been received.
195199
196200
:::image type="content" source="./media/getstarted-dotnet-standard-send-v2/verify-messages-portal.png" alt-text="Image of the Azure portal page to verify that the event hub received the events" lightbox="./media/getstarted-dotnet-standard-send-v2/verify-messages-portal.png":::
197201
@@ -210,15 +214,16 @@ In this quickstart, you use Azure Storage as the checkpoint store. Follow these
210214
211215
[!INCLUDE [storage-checkpoint-store-recommendations](./includes/storage-checkpoint-store-recommendations.md)]
212216
213-
214217
## [Passwordless (Recommended)](#tab/passwordless)
215218
216219
[!INCLUDE [event-hub-storage-assign-roles](../../includes/passwordless/event-hub/event-hub-storage-assign-roles.md)]
220+
217221
## [Connection String](#tab/connection-string)
218222
219223
[Get the connection string to the storage account](../storage/common/storage-account-get-info.md#get-a-connection-string-for-the-storage-account)
220224
221225
Note down the connection string and the container name. You use them in the code to receive events from the event hub.
226+
222227
223228
---
224229
### Create a project for the receiver
@@ -230,6 +235,7 @@ Note down the connection string and the container name. You use them in the code
230235
231236
### Add the NuGet packages to the project
232237
238+
233239
### [Passwordless (Recommended)](#tab/passwordless)
234240
235241
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console** from the menu.
@@ -382,6 +388,8 @@ Replace the contents of **Program.cs** with the following code:
382388
return Task.CompletedTask;
383389
}
384390
```
391+
392+
385393
386394
---
387395
8.6 KB
Loading
17.3 KB
Loading

includes/passwordless/event-hub/event-hub-passwordless-template-tabbed.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: storage
55
author: alexwolfmsft
66
ms.service: azure-storage
77
ms.topic: include
8-
ms.date: 09/09/2022
8+
ms.date: 03/24/2025
99
ms.author: alexwolf
1010
ms.custom: include file
1111
---
@@ -14,7 +14,7 @@ This quick start shows you two ways of connecting to Azure Event Hubs:
1414
- Passwordless (Microsoft Entra authentication)
1515
- Connection string
1616

17-
The first option shows you how to use your security principal in Azure **Active Directory and role-based access control (RBAC)** to connect to an Event Hubs namespace. You don't need to worry about having hard-coded connection strings in your code or in a configuration file or in a secure storage like Azure Key Vault.
17+
The first option shows you how to use your security principal in Azure **Microsoft Entra ID and role-based access control (RBAC)** to connect to an Event Hubs namespace. You don't need to worry about having hard-coded connection strings in your code or in a configuration file or in a secure storage like Azure Key Vault.
1818

1919
The second option shows you how to use a **connection string** to connect to an Event Hubs namespace. If you're new to Azure, you may find the connection string option easier to follow. We recommend using the passwordless option in real-world applications and production environments. For more information, see [Authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md). You can also read more about passwordless authentication on the [overview page](/dotnet/azure/sdk/authentication?tabs=command-line).
2020

@@ -39,6 +39,7 @@ You can authorize access to the service bus namespace using the following steps:
3939

4040
:::image type="content" source="../../../articles/storage/blobs/media/storage-quickstart-blobs-dotnet/sign-in-visual-studio-account-small.png" alt-text="Screenshot showing the account selection.":::
4141

42+
4243
## [Connection String](#tab/connection-string)
4344

4445
## Get the connection string
@@ -54,4 +55,6 @@ A client can use the connection string to connect to the Event Hubs namespace. T
5455

5556
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
5657

58+
59+
5760
---
-4.51 KB
Loading
2.6 KB
Loading

0 commit comments

Comments
 (0)