How solve Kafka Errors Unrecognized Broker Version: Unrecognized Broker Version

Create docker containers from

https://github.com/wurstmeister/kafka-docker.git

docker-compose.yml

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    ports:
      - "9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_CREATE_TOPICS: "test-topic:5:2"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

start docker containers

$ docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                NAMES
1479a7dc96fa        wurstmeister/kafka       "start-kafka.sh"         42 minutes ago      Up 42 minutes       0.0.0.0:32785->9092/tcp                              kafka-docker_kafka_2
08e5017dae2b        wurstmeister/kafka       "start-kafka.sh"         42 minutes ago      Up 42 minutes       0.0.0.0:32786->9092/tcp                              kafka-docker_kafka_3
d4f3d17e81b2        wurstmeister/kafka       "start-kafka.sh"         44 minutes ago      Up 44 minutes       0.0.0.0:32784->9092/tcp                              kafka-docker_kafka_1
72b0fbe553b5        wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   44 minutes ago      Up 44 minutes       22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   kafka-docker_zookeeper_1

checked topics

$ docker exec -it kafka-docker_kafka_3 bash
bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper 172.19.0.3:2181 --list
test-topic
bash-4.4# exit
exit

pip3.7 install kafka-python=1.4.7

maked client by python

import os
from kafka import KafkaConsumer
producer = KafkaConsumer(security_protocol="PLAINTEXT", bootstrap_servers=os.environ.get('KAFKA_HOST', 'localhost:2181'))

try to start returned error

Traceback (most recent call last):
  File "/home/drno/IdeaProjects/prometheus_dirs_and_files_node_exporter/zookeeper_kafka.py", line 9, in <module>
    producer = KafkaConsumer(security_protocol="PLAINTEXT", bootstrap_servers=os.environ.get('KAFKA_HOST', 'localhost:2181'))
  File "/opt/python/python37/lib/python3.7/site-packages/kafka/consumer/group.py", line 354, in __init__
    self._client = KafkaClient(metrics=self._metrics, **self.config)
  File "/opt/python/python37/lib/python3.7/site-packages/kafka/client_async.py", line 240, in __init__
    self.config['api_version'] = self.check_version(timeout=check_timeout)
  File "/opt/python/python37/lib/python3.7/site-packages/kafka/client_async.py", line 908, in check_version
    version = conn.check_version(timeout=remaining, strict=strict, topics=list(self.config['bootstrap_topics_filter']))
  File "/opt/python/python37/lib/python3.7/site-packages/kafka/conn.py", line 1228, in check_version
    raise Errors.UnrecognizedBrokerVersion()
kafka.errors.UnrecognizedBrokerVersion: UnrecognizedBrokerVersion

How solve this problem?

This Post Has One Comment

  1. No Fault

    Solved it by just adding security_protocol=”SSL” to the KafkaProducer as follows:

    from kafka import KafkaProducer
    producer = KafkaProducer(security_protocol=”SSL”, bootstrap_servers=os.environ.get(‘KAFKA_HOST’, ‘localhost:9092’))

Leave a Reply