java code for producer/consumer not able to connect kafka in docker setup
You can see that both the consumer.properties
and the producer.properties
files in that project specify bootstrap.servers=localhost:9092
.
Since you cannot connect to the dockerized kafka service using localhost:9092
, you might try finding the IP address of the docker container, by using, for example, docker inspect kafka | grep IPA
(assuming that the name of your container is kafka
). Then replace localhost
with that IP address in those two properties files.
I am using ches/kafka docker image. Have a look at the explanation of KAFKA_ADVERTISED_HOST_NAME.