Merge pull request #199 from ViniciusSouza/visouza/update-dotnet-version-eventHubKafkaSample
Visouza/update dotnet version event hub kafka sample
This commit is contained in:
Коммит
18b2448906
|
@ -1,13 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Confluent.Kafka" Version="1.1.0" />
|
||||
<!-- Version="1.0.0-beta" />-->
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" /> <!--Version="4.5.0" />-->
|
||||
<PackageReference Include="Confluent.Kafka" Version="1.8.2" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.Configuration;
|
||||
using EventHubsForKafkaSample;
|
||||
|
||||
namespace EventHubsForKafkaSample
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string brokerList = ConfigurationManager.AppSettings["EH_FQDN"];
|
||||
string connectionString = ConfigurationManager.AppSettings["EH_CONNECTION_STRING"];
|
||||
string topic = ConfigurationManager.AppSettings["EH_NAME"];
|
||||
string caCertLocation = ConfigurationManager.AppSettings["CA_CERT_LOCATION"];
|
||||
string consumerGroup = ConfigurationManager.AppSettings["CONSUMER_GROUP"];
|
||||
string? brokerList = ConfigurationManager.AppSettings["EH_FQDN"];
|
||||
string? connectionString = ConfigurationManager.AppSettings["EH_CONNECTION_STRING"];
|
||||
string? topic = ConfigurationManager.AppSettings["EH_NAME"];
|
||||
string? caCertLocation = ConfigurationManager.AppSettings["CA_CERT_LOCATION"];
|
||||
string? consumerGroup = ConfigurationManager.AppSettings["CONSUMER_GROUP"];
|
||||
|
||||
Console.WriteLine("Initializing Producer");
|
||||
Worker.Producer(brokerList, connectionString, topic, caCertLocation).Wait();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Initializing Consumer");
|
||||
Worker.Consumer(brokerList, connectionString, consumerGroup, topic, caCertLocation);
|
||||
Console.ReadKey();
|
||||
|
||||
Console.WriteLine("Initializing Producer");
|
||||
Worker.Producer(brokerList, connectionString, topic, caCertLocation).Wait();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Initializing Consumer");
|
||||
Worker.Consumer(brokerList, connectionString, consumerGroup, topic, caCertLocation);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,13 @@
|
|||
//
|
||||
//Original Confluent sample modified for use with Azure Event Hubs for Apache Kafka Ecosystems
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Confluent.Kafka;
|
||||
|
||||
namespace EventHubsForKafkaSample
|
||||
{
|
||||
class Worker
|
||||
{
|
||||
public static async Task Producer(string brokerList, string connStr, string topic, string cacertlocation)
|
||||
public static async Task Producer(string? brokerList, string? connStr, string? topic, string? cacertlocation)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -45,7 +42,7 @@ namespace EventHubsForKafkaSample
|
|||
}
|
||||
}
|
||||
|
||||
public static void Consumer(string brokerList, string connStr, string consumergroup, string topic, string cacertlocation)
|
||||
public static void Consumer(string? brokerList, string? connStr, string? consumergroup, string? topic, string? cacertlocation)
|
||||
{
|
||||
var config = new ConsumerConfig
|
||||
{
|
||||
|
@ -77,7 +74,7 @@ namespace EventHubsForKafkaSample
|
|||
try
|
||||
{
|
||||
var msg = consumer.Consume(cts.Token);
|
||||
Console.WriteLine($"Received: '{msg.Value}'");
|
||||
Console.WriteLine($"Received: '{msg.Message.Value}'");
|
||||
}
|
||||
catch (ConsumeException e)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Send and Receive Messages in C# using Azure Event Hubs for Apache Kafka Ecosystems
|
||||
|
||||
This quickstart will show how to create and connect to an Event Hubs Kafka endpoint using an example producer and consumer written in C# using .NET Core 2.0. Azure Event Hubs for Apache Kafka Ecosystems supports [Apache Kafka version 1.0](https://kafka.apache.org/10/documentation.html) and later.
|
||||
This quickstart will show how to create and connect to an Event Hubs Kafka endpoint using an example producer and consumer written in C# using .NET 6.0. Azure Event Hubs for Apache Kafka Ecosystems supports [Apache Kafka version 1.0](https://kafka.apache.org/10/documentation.html) and later.
|
||||
|
||||
This sample is based on [Confluent's Apache Kafka .NET client](https://github.com/confluentinc/confluent-kafka-dotnet), modified for use with Event Hubs for Kafka.
|
||||
|
||||
|
@ -10,7 +10,7 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
|
|||
|
||||
In addition:
|
||||
|
||||
* [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
|
||||
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/)
|
||||
* [Git](https://www.git-scm.com/downloads)
|
||||
|
||||
## Create an Event Hubs namespace
|
||||
|
|
Загрузка…
Ссылка в новой задаче