public void Init(CancellationTokenSource tokenSource)
        {
            this.tokenSource = tokenSource;
            timer            = Task.Run(TimerLoop);

            consumer.OnError   += Consumer_OnError;
            consumer.OnMessage += Consumer_OnMessage;

            if (!doNotSubscribeToEndPointQueue)
            {
                consumer.AddSubscriptions(new List <string>()
                {
                    endpointName
                });
            }
        }
        private void CreateConsumer(List <string> topics = null)
        {
            var config = new RdKafka.Config()
            {
                GroupId = endpointName, EnableAutoCommit = false
            };

            bool debugEnabled;

            if (settingsHolder.TryGet <bool>(WellKnownConfigurationKeys.KafkaDebugEnabled, out debugEnabled) && debugEnabled)
            {
                config["debug"] = "all";
            }

            var defaultConfig = new TopicConfig();

            defaultConfig["auto.offset.reset"] = "earliest";

            string sessionTimeout;

            if (settingsHolder.TryGet <string>(WellKnownConfigurationKeys.KafkaSessionTimeout, out sessionTimeout))
            {
                config["session.timeout.ms"] = sessionTimeout;
            }
            else
            {
                config["session.timeout.ms"] = "15000";
            }


            string heartBeatInterval;

            if (settingsHolder.TryGet <string>(WellKnownConfigurationKeys.KafkaHeartBeatInterval, out heartBeatInterval))
            {
                config["heartbeat.interval.ms"] = heartBeatInterval;
            }
            else
            {
                config["heartbeat.interval.ms"] = "5000";
            }

            config.DefaultTopicConfig = defaultConfig;

            if (consumer != null)
            {
                // consumer.Dispose();
            }

            consumer = new EventConsumer(config, connectionString);

            if (topics != null && consumer != null)
            {
                consumer.AddSubscriptions(topics);
            }

            consumer.OnPartitionsAssigned += Consumer_OnPartitionsAssigned;

            consumer.OnPartitionsRevoked += Consumer_OnPartitionsRevoked;

            consumer.OnEndReached += Consumer_OnEndReached;
        }