初始化

This commit is contained in:
2025-11-20 16:20:04 +08:00
commit 4230fa4d27
777 changed files with 232488 additions and 0 deletions

41
mykafka/Program.cs Normal file
View 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
View 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>