0

I have setup docker-compose.yml as

version: '2'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000

  kafka:
    image: confluentinc/cp-kafka:latest
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_ADVERTISED_HOST_NAME: kafka

  client:
    image: python_consumer2
    container_name: python_consumer2
    depends_on: 
      - kafka

While doing docker-compose -f docker-compose.yml up, I am getting below error, except this kafka and zookeeper sevices are up.

python_consumer2 |   File "./transactions_consumer.py", line 8, in <module>
python_consumer2 |     consumer = KafkaConsumer(bootstrap_servers=['localhost:9092'],
python_consumer2 |   File "/usr/local/lib/python3.8/site-packages/kafka/consumer/group.py", line 355, in __init__
python_consumer2 |     self._client = KafkaClient(metrics=self._metrics, **self.config)
python_consumer2 |   File "/usr/local/lib/python3.8/site-packages/kafka/client_async.py", line 242, in __init__
python_consumer2 |     self.config['api_version'] = self.check_version(timeout=check_timeout)
python_consumer2 |   File "/usr/local/lib/python3.8/site-packages/kafka/client_async.py", line 898, in check_version
python_consumer2 |     raise Errors.NoBrokersAvailable()
python_consumer2 | kafka.errors.NoBrokersAvailable: NoBrokersAvailable

My python_consumer.py contains below configurations:

consumer = KafkaConsumer(bootstrap_servers=['localhost:9092'],
                                 auto_offset_reset='earliest',
                                 value_deserializer=lambda m: json.loads(m.decode('utf-8')),consumer_timeout_ms=10000)
consumer.subscribe(['shubham'])

I have already published data in the kafka topic 'shubham' I am subscribing to and I have tried changing bootstrap_servers = ['kafka:29092'], still I am getting the same error. How to fix this?

Shubham Joshi
  • 56
  • 3
  • 11

0 Answers0