confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
2.78k stars 847 forks source link

Support AOT for basic consumer app #2176

Open latop2604 opened 5 months ago

latop2604 commented 5 months ago

Hello, I managed to have my app working with AOT on windows and linux (ubuntu wsl). I tested only with net8.0 framework.

It's a basic consumer app with avalonia UI. But can be summarized as below:

var config = new ConsumerConfig
{
    BootstrapServers = kafkaServers,
    GroupId = "GroupIdPrefix" + Guid.NewGuid(),
    AutoOffsetReset = AutoOffsetReset.Latest,
};

using var consumer = new ConsumerBuilder<string, byte[]>(config)
    .SetErrorHandler((_, e) => {/* ... */})
    .Build();

consumer.Subscribe("my-topic");

while (true)
{
    var result = consumer.Consume(TimeSpan.FromMilliseconds(1000));
    // ...
}

I don't know if it will work with the current list of TargetFrameworks or if we need to add net8.0 explicitly.

Waiting for your feedback.

Should fix https://github.com/confluentinc/confluent-kafka-dotnet/issues/2146

cla-assistant[bot] commented 5 months ago

CLA assistant check
All committers have signed the CLA.

latop2604 commented 3 months ago

Any opinion about this mr @anchitj ?