Exemplo n.º 1
0
        public KafkaTopicProducer(string brokerList, string topic, SslConfig sslConfig)
        {
            var config = new Dictionary <string, object>
            {
                { "bootstrap.servers", brokerList },
                { "group.id", "euler" },
                { "enable.auto.commit", true },  // this is the default
                { "auto.commit.interval.ms", 5000 },
                { "statistics.interval.ms", 60000 },
                { "session.timeout.ms", 6000 }
            };

            SetSslConfig(sslConfig, config);
            var keySerialiser   = new StringSerializer(Encoding.UTF8);
            var valueSerialiser = new StringSerializer(Encoding.UTF8);

            this.producer = new Producer <string, string>(config, keySerialiser, valueSerialiser);

            this.topic = topic;
        }
Exemplo n.º 2
0
        public KafkaTopicConsumer(string brokerList, List <string> topics, SslConfig sslConfig)
        {
            var config = new Dictionary <string, object>
            {
                { "bootstrap.servers", brokerList },
                { "group.id", "euler" },
                { "enable.auto.commit", false },
                { "auto.commit.interval.ms", 5000 },
                { "statistics.interval.ms", 60000 },
                { "session.timeout.ms", 6000 },
                { "auto.offset.reset", "earliest" }
            };

            SetSslConfig(sslConfig, config);

            var keyDeserialiser   = new StringDeserializer(Encoding.UTF8);
            var valueDeserialiser = new StringDeserializer(Encoding.UTF8);

            this.consumer = new Consumer <string, string>(config, keyDeserialiser, valueDeserialiser);

            this.topics = topics;
        }
Exemplo n.º 3
0
        protected static void SetSslConfig(SslConfig sslConfig, Dictionary <string, object> config)
        {
            if (sslConfig != null)
            {
                config.Add("security.protocol", "ssl");

                if (!String.IsNullOrWhiteSpace(sslConfig.CaLocation))
                {
                    config.Add("ssl.ca.location", sslConfig.CaLocation);
                }

                if (!String.IsNullOrWhiteSpace(sslConfig.KeyLocation))
                {
                    config.Add("ssl.key.location", sslConfig.KeyLocation);
                }

                if (!String.IsNullOrWhiteSpace(sslConfig.CertificateLocation))
                {
                    config.Add("ssl.certificate.location", sslConfig.CertificateLocation);
                }
            }
        }