Пример #1
0
        public static KafkaInstance DeployNew(KafkaSettings settings, ILog log)
        {
            var baseDirectory = GetBaseDirectory(settings);

            Directory.CreateDirectory(baseDirectory);

            var kafkaDirectory = GetKafkaDirectory(settings);

            if (Directory.Exists(kafkaDirectory))
            {
                Directory.Delete(kafkaDirectory, true);
            }

            var deployerLog = log.ForContext(nameof(KafkaDeployer));

            deployerLog.Debug("Started Kafka extraction...");
            ResourceHelper.ExtractResource <KafkaInstance>($"Vostok.Kafka.Local.Resources.{KafkaDirectoryName}.tgz", baseDirectory);
            deployerLog.Debug("Finished Kafka extraction.");

            var kafkaPort = FreeTcpPortFinder.GetFreePort();

            var instance = new KafkaInstance(kafkaDirectory, kafkaPort, log);

            GenerateConfig(instance, settings);

            return(instance);
        }
Пример #2
0
        private static void GenerateConfig(KafkaInstance instance, KafkaSettings settings)
        {
            var properties = new Dictionary <string, string>
            {
                ["broker.id"] = "0",
                ["listeners"] = $"PLAINTEXT://localhost:{instance.Port}",
                ["log.dirs"]  = instance.LogDataDirectory,
                ["offsets.topic.replication.factor"]         = "1",
                ["transaction.state.log.replication.factor"] = "1",
                ["transaction.state.log.min.isr"]            = "1",
                ["log.flush.interval.messages"]      = "10000",
                ["log.flush.interval.ms"]            = "1000",
                ["zookeeper.connect"]                = settings.ZooKeeperConnectionString,
                ["zookeeper.connection.timeout.ms"]  = "6000",
                ["group.initial.rebalance.delay.ms"] = "0",
                ["delete.topic.enable"]              = $"{settings.DeleteTopicEnable}"
            };

            new JavaProperties(properties).Save(instance.KafkaPropertiesFile);
        }
Пример #3
0
        public static KafkaInstance DeployNew(KafkaSettings settings, ILog log, bool started = true)
        {
            KafkaInstance kafkaInstance = null;

            try
            {
                kafkaInstance = KafkaDeployer.DeployNew(settings, log);

                if (started)
                {
                    kafkaInstance.Start();
                }

                return(kafkaInstance);
            }
            catch (Exception error)
            {
                log.Error(error, "Error in deploy. Will try to stop and cleanup.");
                kafkaInstance?.Dispose();
                KafkaDeployer.Cleanup(settings);
                throw;
            }
        }
Пример #4
0
 private static string GetKafkaDirectory(KafkaSettings settings)
 {
     return(Path.Combine(GetBaseDirectory(settings), KafkaDirectoryName));
 }
Пример #5
0
 private static string GetBaseDirectory(KafkaSettings settings)
 {
     return(string.IsNullOrEmpty(settings.BaseDirectory) ? Directory.GetCurrentDirectory() : settings.BaseDirectory);
 }
Пример #6
0
 public static void Cleanup(KafkaSettings settings)
 {
     Cleanup(GetKafkaDirectory(settings));
 }