# Logstash (1.5.3) is not able to connect to kafka

**URL:** <https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611>\
**Category:** Logstash\
**Created:** [August 18, 2015, 6:33pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611 "2015-08-18T18:33:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [August 18, 2015, 6:33pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/1 "2015-08-18T18:33:09Z")

</div>

Hi,

I am trying to read some log messages from kafka. Below is my logstash config:-

```
input {
    kafka {
        zk_connect => "kafka:2181"
        group_id => "logstash"
        topic_id => "logstash_logs"
        reset_beginning => false
        consumer_threads => 1
    }
}

output {
  elasticsearch {
    index => "test-2015-08-18"
  }
}

```

My zookeeper.properties in kafka look like below:-

```
dataDir=/tmp/kafka/
clientPort=2181
maxClientCnxns=0

```

The topic `logstash_logs` was created with the below command in kafka machine:-

```
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic logstash_logs

```

On running logstash I am getting the below error in console:-

```
log4j, [2015-08-19T10:41:42.315] WARN: kafka.client.ClientUtils$: Fetching topic metadata with correlation id 5 for topics [Set(logstash_logs)] from broker [id:0,host:localhost,port:9092] failed
java.nio.channels.ClosedChannelException
    at kafka.network.BlockingChannel.send(BlockingChannel.scala:100)
    at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:73)
    at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:72)
    at kafka.producer.SyncProducer.send(SyncProducer.scala:113)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:58)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:93)
    at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:66)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:60)
log4j, [2015-08-19T10:41:42.315] WARN: kafka.consumer.ConsumerFetcherManager$LeaderFinderThread: [logstash_logstash-indexer-1439961100662-86d0d679-leader-finder-thread], Failed to find leader for Set([logstash_logs,0])
kafka.common.KafkaException: fetching topic metadata for topics [Set(logstash_logs)] from broker [ArrayBuffer(id:0,host:localhost,port:9092)] failed
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:72)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:93)
    at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:66)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:60)
Caused by: java.nio.channels.ClosedChannelException
    at kafka.network.BlockingChannel.send(BlockingChannel.scala:100)
    at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:73)
    at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:72)
    at kafka.producer.SyncProducer.send(SyncProducer.scala:113)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:58)
    ... 3 more
```

---

<div class="post-metadata">

**Author:** ![Joe\_Lawson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_lawson/32/3390_2.png) [@Joe\_Lawson](https://discuss.elastic.co/u/Joe_Lawson)\
**Post date:** [August 19, 2015, 2:11am UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/2 "2015-08-19T02:11:11Z")

</div>

Try changing zk\_connect =\> "kafka:2181" to zk\_connect =\> "localhost:2181"

---

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [August 19, 2015, 3:11am UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/3 "2015-08-19T03:11:24Z")

</div>

Kafka/zookeeper not running in the same machine as the logstash. It is running in a different macine. Also I am able to telnet to kafka on port 2181 and also I am able to connect to kafka from the kafka web console. So, I don't think there is any network connectivity issue between both the machines.

---

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [August 19, 2015, 4:12pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/5 "2015-08-19T16:12:12Z")

</div>

Setting `advertised.host.name=kafka` in `server.properties` file solved the issue.

---

<div class="post-metadata">

**Author:** ![Joe\_Lawson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_lawson/32/3390_2.png) [@Joe\_Lawson](https://discuss.elastic.co/u/Joe_Lawson)\
**Post date:** [August 19, 2015, 4:35pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/6 "2015-08-19T16:35:01Z")

</div>

Ah yes, that is a classic gotcha. Sorry I didn't catch it before.

---

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [August 20, 2015, 5:21am UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/7 "2015-08-20T05:21:38Z")

</div>

Thanks Joe 🙂

---

<div class="post-metadata">

**Author:** ![shatesttest](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@shatesttest](https://discuss.elastic.co/u/shatesttest)\
**Post date:** [February 9, 2016, 3:08pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/8 "2016-02-09T15:08:46Z")

</div>

Hi,  
I am having similar problem. where my producer runs on AWS machine and unable to post the messages on topic.

i set up the [advertised.host.name=mariner.twin.com](http://advertised.host.name=mariner.twin.com)  
where [mariner.twin.com](http://mariner.twin.com) is my kafka cluster public host name.

What else need to be set it up ?  
Please help me.

thank you,

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 9, 2016, 3:55pm UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/9 "2016-02-09T15:55:51Z")

</div>

Given that this thread is 5 months old, it is probably better if you create your own thread.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:12am UTC](https://discuss.elastic.co/t/logstash-1-5-3-is-not-able-to-connect-to-kafka/27611/10 "2017-07-06T05:12:29Z")

</div>


