初始化
This commit is contained in:
41
mykafka/Program.cs
Normal file
41
mykafka/Program.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Confluent.Kafka;
|
||||
|
||||
namespace mykafka
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var config = new ProducerConfig
|
||||
{
|
||||
BootstrapServers = "43.138.217.154:9091",
|
||||
SecurityProtocol = SecurityProtocol.SaslPlaintext,
|
||||
SaslMechanism = SaslMechanism.Plain,
|
||||
SaslUsername = "blwmomo",
|
||||
SaslPassword = "blwmomo"
|
||||
};
|
||||
|
||||
// If serializers are not specified, default serializers from
|
||||
// `Confluent.Kafka.Serializers` will be automatically used where
|
||||
// available. Note: by default strings are encoded as UTF8.
|
||||
using (var p = new ProducerBuilder<string, string>(config).Build())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < 10000; i++)
|
||||
{
|
||||
|
||||
var dr = p.ProduceAsync("test-topic", new Message<string, string> { Key = "aaaa", Value = "test" }).Result;
|
||||
Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
|
||||
Task.Delay(100).Wait();
|
||||
}
|
||||
}
|
||||
catch (ProduceException<string, string> e)
|
||||
{
|
||||
Console.WriteLine($"Delivery failed: {e.Error.Reason}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
14
mykafka/mykafka.csproj
Normal file
14
mykafka/mykafka.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Confluent.Kafka" Version="2.11.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user