/// <summary>Creates new instance <see cref="KafkaTransport"/>. Allows you to configure /// all the parameters of the producer and the consumer used in this transport.</summary> /// <param name="rebusLoggerFactory"></param> /// <param name="asyncTaskFactory"></param> /// <param name="brokerList">Initial list of brokers as a CSV list of broker host or host:port.</param> /// <param name="inputQueueName">name of input queue</param> /// <param name="producerConfig">A collection of librdkafka configuration parameters /// (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md) /// and parameters specific to this client (refer to: /// <see cref="T:Confluent.Kafka.ConfigPropertyNames" />). /// At a minimum, 'bootstrap.servers' must be specified.</param> /// <param name="consumerConfig">A collection of librdkafka configuration parameters /// (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md) /// and parameters specific to this client (refer to: /// <see cref="T:Confluent.Kafka.ConfigPropertyNames" />). /// At a minimum, 'bootstrap.servers' and 'group.id' must be /// specified.</param> /// <param name="cancellationToken"></param> public KafkaTransport(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList, string inputQueueName , ProducerConfig producerConfig, ConsumerConfig consumerConfig, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(brokerList)) { throw new NullReferenceException(nameof(brokerList)); } _producerConfig = producerConfig ?? throw new NullReferenceException(nameof(producerConfig)); _producerConfig.BootstrapServers = brokerList; if (consumerConfig != null) { var maxNameLength = 249; if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName)) { throw new ArgumentException("Недопустимые символы или длинна топика (файла)", nameof(inputQueueName)); } Address = inputQueueName; _queueSubscriptionStorage = new KafkaSubscriptionStorage(rebusLoggerFactory, asyncTaskFactory, brokerList , inputQueueName, consumerConfig, cancellationToken); } _log = rebusLoggerFactory.GetLogger <KafkaTransport>(); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; }
/// <summary>Creates new instance <see cref="KafkaTransport"/>. Performs a simplified /// configuration of the parameters of the manufacturer and the consumer used in this transport.</summary> /// <param name="rebusLoggerFactory"></param> /// <param name="asyncTaskFactory"></param> /// <param name="brokerList">Initial list of brokers as a CSV list of broker host or host:port.</param> /// <param name="inputQueueName">name of input queue</param> /// <param name="groupId">Id of group</param> /// <param name="cancellationToken"></param> public KafkaTransport(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList , string inputQueueName, string groupId = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(brokerList)) { throw new NullReferenceException(nameof(brokerList)); } _producerConfig = new ProducerConfig { BootstrapServers = brokerList, ApiVersionRequest = true, QueueBufferingMaxKbytes = 10240, //{ "socket.blocking.max.ms", 1 }, // **DEPRECATED * *No longer used. #if DEBUG Debug = "msg", #endif MessageTimeoutMs = 3000, }; _producerConfig.Set("request.required.acks", "-1"); _producerConfig.Set("queue.buffering.max.ms", "5"); if (!string.IsNullOrWhiteSpace(inputQueueName)) { var maxNameLength = 249; if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName)) { throw new ArgumentException("Недопустимые символы или длинна топика (файла)", nameof(inputQueueName)); } Address = inputQueueName; _queueSubscriptionStorage = new KafkaSubscriptionStorage(rebusLoggerFactory, asyncTaskFactory, brokerList , inputQueueName, groupId, cancellationToken); } _log = rebusLoggerFactory.GetLogger <KafkaTransport>(); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; }