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!");
        }
    }
}
