public 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) .Build(); } } finally { _connectionLock.Release(); } }
public ConnectionPool(ILogger <ConnectionPool> logger, KafkaOptions options) { _logger = logger; _pool = new ConcurrentQueue <Producer>(); _maxSize = options.ConnectionPoolSize; _activator = CreateActivator(options); ServersAddress = options.Servers; _logger.LogDebug("Kafka configuration of CAP :\r\n {0}", JsonConvert.SerializeObject(options.AsKafkaConfig(), Formatting.Indented)); }
private void InitKafkaClient() { _kafkaOptions.MainConfig["group.id"] = _groupId; var config = _kafkaOptions.AsKafkaConfig(); _consumerClient = new Consumer <Null, string>(config, null, StringDeserializer); _consumerClient.OnConsumeError += ConsumerClient_OnConsumeError; _consumerClient.OnMessage += ConsumerClient_OnMessage; _consumerClient.OnError += ConsumerClient_OnError; }
private void InitKafkaClient() { lock (_kafkaOptions) { _kafkaOptions.MainConfig["group.id"] = _groupId; _kafkaOptions.MainConfig["auto.offset.reset"] = "earliest"; var config = _kafkaOptions.AsKafkaConfig(); _consumerClient = new ConsumerBuilder <Null, string>(config) .SetErrorHandler(ConsumerClient_OnConsumeError) .Build(); } }
public IProducer <Null, string> RentProducer() { if (_producerPool.TryDequeue(out var producer)) { Interlocked.Decrement(ref _pCount); return(producer); } producer = new ProducerBuilder <Null, string>(_options.AsKafkaConfig()).Build(); return(producer); }
private static Func <Producer> CreateActivator(KafkaOptions options) { return(() => new Producer(options.AsKafkaConfig())); }
public ConnectionPool(ILogger <ConnectionPool> logger, IOptions <KafkaOptions> options) { _options = options.Value; _producerPool = new ConcurrentQueue <IProducer <Null, string> >(); _maxSize = _options.ConnectionPoolSize; logger.LogDebug("Kafka configuration of CAP :\r\n {0}", JsonConvert.SerializeObject(_options.AsKafkaConfig(), Formatting.Indented)); }