/// <summary> /// Initializes a new instance of the <see cref="KafkaConsumer{T1,T2}"/> class. /// </summary> public KafkaConsumer( KafkaConsumerProperties consumerProperties, IDeserializer <T1> deserializer1, IDeserializer <T2> deserializer2) { this.kafkaConsumerProperties = consumerProperties; var configuration = this.GetKafkaConfiguration(consumerProperties); this.consumer = new Consumer <T1, T2>(configuration, deserializer1, deserializer2); this.consumer.Subscribe(this.kafkaConsumerProperties.TopicName); }
/// <summary> /// The get kafka configuration. /// </summary> private Dictionary <string, object> GetKafkaConfiguration(KafkaConsumerProperties consumerProperties) { string serverAddresses = string.Join(",", consumerProperties.ServerAddresses); var configuration = new Dictionary <string, object> { [ConsumerGroupId] = consumerProperties.ConsumerGroupId, [ServerAddresses] = serverAddresses }; if (consumerProperties.AutoCommitIntervalInMilliseconds != null) { configuration.Add(AutoCommitIntervalInMilliseconds, consumerProperties.AutoCommitIntervalInMilliseconds); } if (consumerProperties.AutoOffsetReset != null) { configuration.Add(AutoOffsetReset, consumerProperties.AutoOffsetReset); } if (consumerProperties.MaximumParititionFetchBytes != null) { configuration.Add(MaximumPartitionFetchBytes, consumerProperties.MaximumParititionFetchBytes); } if (!string.IsNullOrWhiteSpace(consumerProperties.LoggingLevel)) { configuration.Add(LoggingLevel, consumerProperties.LoggingLevel); } if (consumerProperties.UseSecureKafka) { configuration.Add(SecurityProtocol, consumerProperties.SecurityProtocol); configuration.Add(SslCertificateLocation, consumerProperties.CertificateLocation); configuration.Add(SslKeyLocation, consumerProperties.KeyLocation); configuration.Add(SslKeyPassword, consumerProperties.KeyPassword); configuration.Add(SslCaLocation, consumerProperties.CertificateAuthorityLocation); } return(configuration); }