# Inputs.kafka\_consumer not working

**URL:** https://community.influxdata.com/t/inputs-kafka-consumer-not-working/19648
**Category:** Telegraf
**Tags:** kafka
**Created:** [April 29, 2021, 2:22am UTC](https://community.influxdata.com/t/inputs-kafka-consumer-not-working/19648 "2021-04-29T02:22:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Pratik\_Das\_Baghel](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/pratik_das_baghel/32/5698_2.png) [@Pratik\_Das\_Baghel](https://community.influxdata.com/u/Pratik_Das_Baghel)
#### Post date: [April 29, 2021, 2:22am UTC](https://community.influxdata.com/t/inputs-kafka-consumer-not-working/19648/1 "2021-04-29T02:22:16Z")

</div>

I wanted to use apache kafka as input for telegraf. I am running docker containers. Docker image is from - [GitHub - wurstmeister/kafka-docker: Dockerfile for Apache Kafka](https://github.com/wurstmeister/kafka-docker)  
This is my docker-compose file:

> version: ‘3’  
> services:  
> zookeeper:  
> image: wurstmeister/zookeeper  
> ports:  
> - “2181:2181”  
> kafka:  
> image: wurstmeister/kafka  
> ports:  
> - “9092:9092”  
> environment:  
> - KAFKA\_ADVERTISED\_HOST\_NAME=localhost  
> - KAFKA\_ADVERTISED\_PORT=9092  
> - KAFKA\_ZOOKEEPER\_CONNECT=zookeeper:2181  
> - KAFKA\_CREATE\_TOPICS=“test:1:1”  
> depends\_on:  
> - zookeeper  
> volumes:  
> - /var/run/docker.sock:/var/run/docker.sock

I have pushed data to topic and it’s working. I am getting the output. But for telegraf config i am getting - kafka: client has run out of available brokers to talk to (Is your cluster reachable?)

> [[inputs.kafka\_consumer]]  
> brokers = [“localhost:9092”]  
> topics = [“test”]  
> version = “2.7.0”

Then i referred here - [Possibility to access kafka contaner from other container · Issue #575 · wurstmeister/kafka-docker · GitHub](https://github.com/wurstmeister/kafka-docker/issues/575)

> version: ‘2’  
> services:  
> zookeeper:  
> image: wurstmeister/zookeeper:3.4.6  
> ports:  
> - “2181:2181”  
> kafka:  
> image: wurstmeister/kafka:2.11-2.0.0  
> depends\_on:  
> - zookeeper  
> ports:  
> - “9092:9092”  
> expose:  
> - “9093”  
> environment:  
> KAFKA\_ADVERTISED\_LISTENERS: INSIDE://kafka:9093,OUTSIDE://localhost:9092  
> KAFKA\_LISTENER\_SECURITY\_PROTOCOL\_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT  
> KAFKA\_LISTENERS: INSIDE://0.0.0.0:9093,OUTSIDE://0.0.0.0:9092  
> KAFKA\_ZOOKEEPER\_CONNECT: zookeeper:2181  
> KAFKA\_INTER\_BROKER\_LISTENER\_NAME: INSIDE  
> KAFKA\_CREATE\_TOPICS: ‘Sometopic:1:1’  
> KAFKA\_AUTO\_CREATE\_TOPICS\_ENABLE: ‘true’  
> volumes:  
> - /var/run/docker.sock:/var/run/docker.sock

Again producer and consumer is working fine but with telegraf same error is showing. For broker i tried all configs - kafka:9093,localhost:9092,kafka:9092,localhost:9093 still every time error is showing. What to do now?

---

<div class="post-metadata">

### Author: ![helenosheaa](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/helenosheaa/32/7090_2.png) [@helenosheaa](https://community.influxdata.com/u/helenosheaa)
#### Post date: [April 30, 2021, 2:46pm UTC](https://community.influxdata.com/t/inputs-kafka-consumer-not-working/19648/2 "2021-04-30T14:46:39Z")

</div>

Hi @Pratik_Das_Baghel,

I used the below docker-compose file:

```
version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    environment:
      - JAVA_OPTS="-Xms256m -Xmx256m"
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    environment:
      - KAFKA_ADVERTISED_HOST_NAME=localhost
      - KAFKA_ADVERTISED_PORT=9092
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
      - JAVA_OPTS="-Xms256m -Xmx256m"
    ports:
      - "9092:9092"
    depends_on:
      - zookeeper

```

and this config:

```
[[inputs.kafka_consumer]]
brokers = ["localhost:9092"]
topics = ["test"]
version = "2.7.0"

```

And it connected to the broker, initialized a new client and added subscription to test/0.

Could you try using this docker-compose and see if you get the same error message?

What version of telegraf are you using?

Do you have debug set to true in the agent portion of your config?

This [closed issue](https://github.com/influxdata/telegraf/issues/6072) might have some pointers also as it was a similar error message.

I also found a [stack overflow issue](https://stackoverflow.com/questions/52438822/docker-kafka-w-python-consumer/52440056#52440056) about setting up docker-compose for kafka which may be useful also.

Let me know if that helps.  
Thanks!
