public KafkaMessageBus(MessageBusSettings settings, KafkaMessageBusSettings kafkaSettings)
            : base(settings)
        {
            AssertSettings(settings);

            KafkaSettings = kafkaSettings;

            Log.Info("Creating producer");
            _producer = CreateProducer();
            Log.InfoFormat("Producer has been assigned name: {0}", _producer.Name);

            Log.Info("Creating subscribers");
            foreach (var subscribersByGroup in settings.Consumers.GroupBy(x => x.Group))
            {
                var group = subscribersByGroup.Key;

                foreach (var subscribersByMessageType in subscribersByGroup.GroupBy(x => x.MessageType))
                {
                    var messageType = subscribersByMessageType.Key;

                    Log.InfoFormat("Creating consumer for topics {0}, group {1}, message type {2}", string.Join(",", subscribersByMessageType.Select(x => x.Topic)), group, messageType);
                    var consumer = new KafkaGroupConsumer(this, group, messageType, subscribersByMessageType.ToList());
                    _groupConsumers.Add(consumer);
                }
            }

            if (settings.RequestResponse != null)
            {
                Log.InfoFormat("Creating response consumer for topic {0} and group {1}", settings.RequestResponse.Group, settings.RequestResponse.Topic);
                _groupConsumers.Add(new KafkaResponseConsumer(this, settings.RequestResponse));
            }
        }
        public TopicConsumerInstances(ConsumerSettings settings, KafkaGroupConsumer groupConsumer, KafkaMessageBus messageBus)
        {
            _settings      = settings;
            _messageBus    = messageBus;
            _groupConsumer = groupConsumer;

            _consumerInstanceOnHandleMethod = settings.ConsumerType.GetMethod("OnHandle", new[] { groupConsumer.MessageType, typeof(string) });
            _consumerInstances = ResolveInstances(settings, messageBus);
            _consumerQueue     = new BufferBlock <object>();
            _consumerInstances.ForEach(x => _consumerQueue.Post(x));

            if (_settings.ConsumerMode == ConsumerMode.RequestResponse)
            {
                var taskType = typeof(Task <>).MakeGenericType(_settings.ResponseType);
                _taskResult = taskType.GetProperty("Result");
            }
        }