6

I have installed kafka_2.11-1.1.0 and set advertised listener to advertised.listeners=PLAINTEXT://<my-ip>:9092 (in $KAFKA_HOME/config/server.properties).

I can connect and write to my kafka using java code and see my cluster via kafka-tool from another server but I can't write messages to my topic from my local machine (the one that I have installed kafka cluster on it).

I have also tried to set listeners value to listeners = PLAINTEXT://:9092 but there is no change. What should I do to my kafka to make it reachable and writable from both outside and inside of the localhost?

Mickael Maison
  • 25,067
  • 7
  • 71
  • 68
Vahid F
  • 377
  • 1
  • 7
  • 21
  • 2
    "I can't write messages to my topic from my local machine" -> do you get an error message? How are you trying to write them? – Robin Moffatt Dec 17 '18 at 12:29
  • I try to write an application like the example described here: https://dzone.com/articles/kafka-producer-and-consumer-example I mean from a java code. – Vahid F Dec 17 '18 at 12:33
  • 1
    Can you show a netstat output for port 9092? And again, are there errors you're getting? – OneCricketeer Dec 17 '18 at 13:41
  • I used telned from this server to itself (`telnet localhost 9092`) and it tells me `Trying 127.0.0.1... Connected to localhost.` and after pressing enter it says `Connection to localhost closed by foreign host.`. What should I do with netstat? – Vahid F Dec 17 '18 at 13:47

3 Answers3

10

In the server.properties use these two following properties

listeners=PLAINTEXT://0.0.0.0:9092 
advertised.listeners=PLAINTEXT://<your ip>:9092
Bitswazsky
  • 4,242
  • 3
  • 29
  • 58
3

I finally solved the issue by changing my code's org.apache.kafka library from version 1.1.0 to version 2.1.0.

I mention that all of these libraries were imported (downloaded) and used via mvnrepository.com.

Also, our kafka producer and consumer code pattern were written using this article: https://dzone.com/articles/kafka-producer-and-consumer-example.

Vahid F
  • 377
  • 1
  • 7
  • 21
  • I hope other developers, not to have such mind blowing issues in the future!! – Vahid F Dec 22 '18 at 07:06
  • I'm not sure but, maybe that's because when you upgrade your kafka version you might need to upgrade your libraries version too. – Vahid F Dec 22 '18 at 07:34
2

Have a look in the below following links, it may be helpful for your scenario,

Shiva
  • 63
  • 1
  • 8
  • My issue is with internal connections not the external ones. When I set my ip or localhost or 127.0.0.1 kafka clients are not able to connect to my kafka broker. – Vahid F Dec 18 '18 at 06:30
  • Then, have you checked the hosts file of your system? Is ip or locahost or 127.0.0.1 reachable via ping? – Shiva Dec 18 '18 at 08:14
  • I have checked them again and all of them are alive and reachable. – Vahid F Dec 18 '18 at 09:53