1

I have a server with Zookeeper and Kafka in private network on 10.242.44.55. I have forwarded port on gateway from [public_ip]:39092 to 10.242.44.55:9092. I took the following settings for Kafka from another question:

listeners=INTERNAL://:9092,EXTERNAL://:39092
advertised.listeners=INTERNAL://10.242.44.55:9092,EXTERNAL://[public_ip]:39092
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
inter.broker.listener.name=INTERNAL

Everything works fine in private network. I can produce and consume messages from different computers. Unfortunatelly when I tried to produce a message from outside I got an error:

pers@pc:/opt/kafka$ bin/kafka-console-producer.sh —broker-list [public_ip]:39092 —topic test
>testMessage
>[2018-03-24 17:51:04,393] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for test-1: 1505 ms has passed since batch creation plus linger time
[2018-03-24 17:53:13,970] WARN [Producer clientId=console-producer] Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

The same time I can reach this socket with telnet:

pers@pc:/opt/kafka$ telnet [public_ip] 39092
Trying [public_ip]...
Connected to [public_ip].
Escape character is '^]'.
test
Connection closed by foreign host.

I saw that another man had such problem, but there are no solutions. Anybody knows what I'm doing worng?

V. Perfilev
  • 438
  • 1
  • 7
  • 18

2 Answers2

2

I accidentally solved my problem. Kafka works fine when the same ports are used in ports forwarding.

This is part of my broker's config:

listeners=EXTERNAL://:39092,INTERNAL://:9092
advertised.listeners=EXTERNAL://77.1.1.1:39092,INTERNAL://10.1.1.1:9092
listener.security.protocol.map=EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
inter.broker.listener.name=INTERNAL
V. Perfilev
  • 438
  • 1
  • 7
  • 18
  • @v-perfilev:What do you mean by `Kafka works fine when the same ports are used in ports forwarding.` I don't see the difference between your solution config and your problem config. – Lars Skaug Jan 21 '21 at 21:48
0

Here is working port forwarding simple config of kafka. port 19082 should be open on external ip

    broker.id=0
    advertised.host.name=192.168.129.36
    listeners=PLAINTEXT://:9092
    advertised.listeners=PLAINTEXT://122.112.92.146:19092
Charudatta Joshi
  • 119
  • 1
  • 1
  • 5