1. .NET
  2. Tutorial

Create Project

Create a new directory anywhere you’d like for this project:

mkdir kafka-dotnet-getting-started
cd kafka-dotnet-getting-started
mkdir producer
mkdir consumer

Next we’ll create two different C# project files, one for the producer and one for the consumer. The project files specify the output type of project artifact which is an executable for both the producer and consumer. It also specifies the required dependencies that the .NET platform needs for the project.

Copy the following into a project file named producer.csproj in the producer subdirectory:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <StartupObject>Producer</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Confluent.Kafka" Version="2.3" />
  </ItemGroup>

</Project>

Copy the following into a project file named consumer.csproj in the consumer subdirectory:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <StartupObject>Consumer</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Confluent.Kafka" Version="2.3" />
  </ItemGroup>

</Project>
Previous
Prerequisites