Problem phenomenon:
Today, I wanted to debug the service on my computer. I found that when calling the interface through the gateway, an error related to Kafka was reported, as follows:
java.net.UnknownHostException: kafkahost
Problem analysis:
It can be seen from the error message that the host named kafkahost cannot be recognized.
By viewing the configuration of a service instance of Kafka cluster configuration on Linux server, you can find:
listeners=PLAINTEXT://kafkahost:0091
This configuration uses the {kafkahost} mentioned in the error message. You can see that this service instance listens to the IP port} kafkahost: 0091; By viewing the/etc/hosts file of the Linux server, you can see:
Kafkahost points to the Linux server IP.
Since I accessed the Kafka service on the Linux server in the native service, I naturally could not resolve to kafkahost. Therefore, you need to add the corresponding configuration in the hosts file of this machine!
Solution:
Find the hosts file path of this machine:
C:\Windows\System32\drivers\etc
Add the following configuration at the end of the file to identify kafkahost as the Linux server IP:
Restart the local service and call the interface again without any error: