Exemple #1
0
        public ConsumerGroupHost Initialize(ILog log, AirlockEnvironmentVariables environmentVariables)
        {
            var environment            = environmentVariables.GetValue("VOSTOK_ENV", "dev");
            var metricRoutingKeyPrefix = RoutingKey.CreatePrefix("vostok", environment, ServiceName);
            var graphiteUri            = GetGraphiteUri(log, environmentVariables);
            var graphiteSinkConfig     = new GraphiteSinkConfig
            {
                GraphiteHost = graphiteUri.Host,
                GraphitePort = graphiteUri.Port
            };

            log.Info($"GraphiteSinkConfig: {graphiteSinkConfig.ToPrettyJson()}");
            graphiteSink = new GraphiteSink(graphiteSinkConfig, log);
            var rootMetricScope = new RootMetricScope(new MetricConfiguration
            {
                Reporter = new GraphiteMetricReporter(graphiteSink, metricRoutingKeyPrefix, log)
            });
            var consumerGroupHostSettings = GetConsumerGroupHostSettings(log, environmentVariables);

            consumerMetrics = new ConsumerMetrics(consumerGroupHostSettings.FlushMetricsInterval, rootMetricScope);

            DoInitialize(log, rootMetricScope, environmentVariables, out var routingKeyFilter, out var processorProvider);

            return(new ConsumerGroupHost(consumerGroupHostSettings, log, consumerMetrics, routingKeyFilter, processorProvider));
        }
Exemple #2
0
        protected static Uri GetGraphiteUri(ILog log, AirlockEnvironmentVariables environmentVariables)
        {
            var graphiteEndpoint = environmentVariables.GetValue("GRAPHITE_ENDPOINT", defaultGraphiteEndpoint);
            var graphiteUri      = new Uri($"tcp://{graphiteEndpoint}");

            log.Info($"GraphiteUri: {graphiteUri}");
            return(graphiteUri);
        }
Exemple #3
0
        private ConsumerGroupHostSettings GetConsumerGroupHostSettings(ILog log, AirlockEnvironmentVariables environmentVariables)
        {
            var consumerGroupPrefix       = environmentVariables.GetValue("CONSUMER_GROUP_PREFIX", $"{GetType().Name}@{Dns.GetHostName()}");
            var consumerGroupId           = $"{consumerGroupPrefix}_{ServiceName}";
            var kafkaBootstrapEndpoints   = environmentVariables.GetValue("KAFKA_BOOTSTRAP_ENDPOINTS", defaultKafkaBootstrapEndpoints);
            var autoResetOffsetPolicy     = environmentVariables.GetEnumValue("KAFKA_AUTO_OFFSET_RESET", AutoResetOffsetPolicy.Latest);
            var consumerGroupHostSettings = new ConsumerGroupHostSettings(kafkaBootstrapEndpoints, consumerGroupId, ProcessorHostSettings, autoResetOffsetPolicy);

            log.Info($"ConsumerGroupHostSettings: {consumerGroupHostSettings.ToPrettyJson()}");
            return(consumerGroupHostSettings);
        }
        public void Run()
        {
            var log = Logging.Configure();

            AppDomain.CurrentDomain.UnhandledException += (_, eventArgs) =>
            {
                log.Fatal("Unhandled exception in curreant AppDomain", (Exception)eventArgs.ExceptionObject);
                Environment.ExitCode = 1;
            };
            TaskScheduler.UnobservedTaskException += (_, eventArgs) =>
            {
                log.Fatal("UnobservedTaskException", eventArgs.Exception);
                eventArgs.SetObserved();
            };
            Console.CancelKeyPress += (_, eventArgs) =>
            {
                log.Info("Ctrl+C is pressed -> terminating...");
                stopSignal.Set();
                eventArgs.Cancel = true;
            };
            AssemblyLoadContext.Default.Unloading += assemblyLoadContext =>
            {
                log.Info("AssemblyLoadContext.Default.Unloading event is fired -> terminating...");
                stopSignal.Set();
                terminationSignal.Wait(Timeout.Infinite);
                log.Info("Termination signal is set -> exiting...");
                Environment.ExitCode = 0;
            };
            try
            {
                log.Info($"Consumer application is starting: {typeof (TConsumerApp).Name}");
                using (var consumerApplication = new TConsumerApp())
                {
                    var environmentVariables = AirlockEnvironmentVariables.CreateFromProcessEnvironment(log);
                    using (consumerApplication.Initialize(log, environmentVariables))
                    {
                        log.Info($"Consumer application is started: {typeof (TConsumerApp).Name}");
                        stopSignal.Wait(Timeout.Infinite);
                        log.Info($"Stopping consumer group host for: {typeof (TConsumerApp).Name}");
                    }
                }
                log.Info($"Consumer application is stopped: {typeof (TConsumerApp).Name}");
                terminationSignal.Set();
            }
            catch (Exception e)
            {
                log.Fatal("Unhandled exception on the main thread", e);
                Environment.ExitCode = 3;
            }
        }
Exemple #5
0
 protected abstract void DoInitialize(ILog log, IMetricScope rootMetricScope, AirlockEnvironmentVariables environmentVariables, out IRoutingKeyFilter routingKeyFilter, out IAirlockEventProcessorProvider processorProvider);