Example #1
0
        public void Initialize(string configuration)
        {
            this.Config = JsonConvert.DeserializeObject <Dto.Config>(configuration);

            var producerConfig = new ProducerConfig()
            {
                BootstrapServers = string.Join(',', this.Config.Nodes.Select(n => n.AbsoluteUri)),
                SaslMechanism    = SaslMechanism.ScramSha512,
                SecurityProtocol = SecurityProtocol.SaslSsl,
                SaslUsername     = this.Config.Username,
                SaslPassword     = this.Config.Password,

                BatchSize                 = this.Config.MaxBatchBytes,
                BatchNumMessages          = this.Config.MaxBatchMessageCount,
                Acks                      = (Acks?)this.Config.AckType,
                LingerMs                  = this.Config.BatchLingerMs,
                MessageTimeoutMs          = this.Config.MessageTimeoutMs,
                MessageSendMaxRetries     = this.Config.MaxMessageRetries,
                QueueBufferingMaxMessages = this.Config.MaxMessageQueueCount
            };

            var dllPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "librdkafka",
                Environment.Is64BitProcess ? "x64" : "x86",
                "librdkafka.dll"
                );

            Library.Load(dllPath);

            this.Producer = new ProducerBuilder <Null, string>(producerConfig).Build();
        }
Example #2
0
 public void Clean()
 {
     this.Producer.Dispose();
     this.Config = null;
 }