About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
windows_first
⚠️
missing_linux_example
⚠️
windows_tools
Summary:
The documentation demonstrates a clear Windows bias by exclusively referencing Microsoft Visual Studio as the development environment, using only Windows-specific tooling (such as the Visual Studio UI and Package Manager Console), and omitting any instructions or examples for Linux or cross-platform development. There are no command-line instructions for .NET CLI or guidance for using editors like VS Code, nor are there any Linux-specific setup or authentication steps. All package installation and project creation steps are described in terms of Visual Studio's GUI and Windows-centric workflows.
Recommendations:
- Add parallel instructions for Linux and macOS users, including how to use the .NET CLI (e.g., `dotnet new console`, `dotnet add package ...`) for project creation and package management.
- Include examples for using cross-platform editors such as Visual Studio Code, and provide guidance for authentication methods that work outside Visual Studio (e.g., Azure CLI, environment variables).
- Explicitly state that the quickstart works on Windows, Linux, and macOS, and provide any platform-specific prerequisites or troubleshooting steps.
- Replace or supplement screenshots and step-by-step instructions that are Visual Studio-specific with equivalent command-line or VS Code workflows.
- Ensure that all code generation and build steps are described in a way that is not dependent on Windows-only tools or interfaces.
Create pull request
Flagged Code Snippets
1. In the Azure portal, you can verify that the event hub received the events. Switch to **Messages** view in the **Metrics** section. Refresh the page to update the chart. It might take a few seconds for it to show that it received the messages.
:::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":::
## Consume events from event hubs with schema validation
This section shows how to write a .NET Core console application that receives events from an event hub and use schema registry to deserialize event data.
### Additional prerequisites
- Create the storage account to be used the event processor.
### Create consumer application
1. In the Solution Explorer window, right-click the **SRQuickStart** solution, select **Add**, and select **New Project**.
1. Select **Console application**, and select **Next**.
1. Enter **OrderConsumer** for the **Project name**, and select **Create**.
1. In the **Solution Explorer** window, right-click **OrderConsumer**, and select **Set as a Startup Project**.
### Add the Event Hubs NuGet package
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
1. In the **Package Manager Console** window, confirm that **OrderConsumer** is selected for the **Default project**. If not, use the dropdown list to select **OrderConsumer**.
1. Run the following command to install the required NuGet packages. Press **ENTER** to run the last command.
## Add user to Schema Registry Reader role
Add your user account to the **Schema Registry Reader** role at the namespace level. You can also use the **Schema Registry Contributor** role, but that's not necessary for this quickstart.
1. On the **Event Hubs Namespace** page, on the left menu, select **Access control (IAM)**.
1. On the **Access control (IAM)** page, select **+ Add** > **Add role assignment**.
1. On the **Roles** page, select **Schema Registry Reader**, and then select **Next**.
1. Use the **+ Select members** link to add your user account to the role, and then select **Next**.
1. On the **Review + assign** page, select **Review + assign**.
## Produce events to event hubs with schema validation
### Create console application for event producer
1. Start Visual Studio.
1. Select **Create a new project**.
1. On the **Create a new project** dialog, do the following steps. If you don't see this dialog, select **File** on the menu, select **New**, and then select **Project**.
1. Select **C#** for the programming language.
1. Select **Console** for the type of the application.
1. Select **Console Application** from the results list.
1. Then, select **Next**.
:::image type="content" source="./media/getstarted-dotnet-standard-send-v2/new-send-project.png" alt-text="Screenshot showing the Visual Studio New Project dialog.":::
1. Enter **OrderProducer** for the project name, **SRQuickStart** for the solution name, and then select **OK** to create the project.
### Add the Event Hubs NuGet package
1. Select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
1. Run the following commands to install **Azure.Messaging.EventHubs** and other NuGet packages. Press **ENTER** to run the last command.
1. Authenticate producer applications to connect to Azure by using Visual Studio. For more information, see [Azure Identity client library for .NET](/dotnet/api/overview/azure/identity-readme#authenticate-via-visual-studio).
1. Sign in to Azure using the user account that's a member of the `Schema Registry Reader` role at the namespace level. For information about schema registry roles, see [Azure role-based access control](schema-registry-concepts.md#azure-role-based-access-control).
### Code generation using the Avro schema
1. Use the same content you used to create the schema to create a file named `Order.avsc`. Save the file in the project or solution folder.
1. Use this schema file to generate code for .NET. You can use any external code generation tool such as [avrogen](https://www.nuget.org/packages/Apache.Avro.Tools/) for code generation. For example, run ` avrogen -s .\Order.avsc .` to generate code.
1. After you generate code, you see the file named `Order.cs` in the `\Microsoft\Azure\Data\SchemaRegistry\example` folder. For the Avro schema here, it generates the C# types in `Microsoft.Azure.Data.SchemaRegistry.example` namespace.
1. Add the `Order.cs` file to the `OrderProducer` project.
### Write code to serialize and send events to the event hub
1. Add the following code to the `Program.cs` file. See the code comments for details. High-level steps in the code are:
1. Create a producer client that you can use to send events to an event hub.
1. Create a schema registry client that you can use to serialize and validate data in an `Order` object.
1. Create a new `Order` object using the generated `Order` type.
1. Use the schema registry client to serialize the `Order` object to `EventData`.
1. Create a batch of events.
1. Add the event data to the event batch.
1. Use the producer client to send the batch of events to the event hub.
1. Authenticate producer applications to connect to Azure by using Visual Studio, as shown in [Azure Identity client library for .NET](/dotnet/api/overview/azure/identity-readme#authenticate-via-visual-studio).
1. Sign-in to Azure using the user account that's a member of the `Schema Registry Reader` role at the namespace level. For information about schema registry roles, see [Azure role-based access control](schema-registry-concepts.md#azure-role-based-access-control).
1. Add the `Order.cs` file you generated as part of creating the producer app to the **OrderConsumer** project.
1. Right-click **OrderConsumer** project, and select **Set as Startup project**.
### Write code to receive events and deserialize them using Schema Registry
1. Add the following code to the `Program.cs` file. See the code comments for details. High-level steps in the code are:
1. Create a consumer client that you can use to send events to an event hub.
1. Create a blob container client for the blob container in the Azure blob storage.
1. Create an event processor client and register event and error handlers.
1. In the event handler, create a schema registry client that you can use to deserialize event data into an `Order` object.
1. Deserialize the event data into an `Order` object using the serializer.
1. Print the information about the received order.