private void Connect() { if (_consumerClient != null) { return; } _connectionLock.Wait(); try { if (_consumerClient == null) { _kafkaOptions.MainConfig.Set("group.id", _groupId); _kafkaOptions.MainConfig.Set("auto.offset.reset", "earliest"); var config = _kafkaOptions.AsKafkaConfig(); _consumerClient = new ConsumerBuilder <string, byte[]>(config) .SetErrorHandler(ConsumerClient_OnConsumeError) .SetLogHandler(ConsumerClient_OnLog) .Build(); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw ex; } finally { _connectionLock.Release(); } }
private void Connect() { if (_consumerClient != null) { return; } _connectionLock.Wait(); try { if (_consumerClient == null) { _kafkaOptions.MainConfig["group.id"] = _groupId; _kafkaOptions.MainConfig["auto.offset.reset"] = "earliest"; var config = _kafkaOptions.AsKafkaConfig(); _consumerClient = new ConsumerBuilder <string, byte[]>(config) .SetErrorHandler(ConsumerClient_OnConsumeError) .SetLogHandler(ConsumerClient_OnLog) .Build(); } } finally { _connectionLock.Release(); } }
public IProducer <string, byte[]> RentProducer() { if (_producerPool.TryDequeue(out var producer)) { Interlocked.Decrement(ref _pCount); return(producer); } producer = new ProducerBuilder <string, byte[]>(_options.AsKafkaConfig()).Build(); return(producer); }
public ConnectionPool(ILogger <ConnectionPool> logger, KafkaOptions options) { _options = options; _producerPool = new ConcurrentQueue <IProducer <string, byte[]> >(); _maxSize = _options.ConnectionPoolSize; logger.LogDebug("Transport Kafka configuration: {0}", JsonConvert.SerializeObject(_options.AsKafkaConfig(), Formatting.Indented)); }