I just wanted to implement Spring boot and Apache Kafka via docker-compose. Firstly I installed the Apache Kafka Docker image via this link: https://hub.docker.com/r/ches/kafka/ and then install jplock/zookeeper via this command shown below.
docker run -d — name zookeeper — publish 2181:2181 jplock/zookeeper:latest
Then I run this command (docker ps
) to determine if all images work. their status of all these images is up. That's why they work flawlessly.
Then I run the app and sent a message via Postman. The post url is localhost:8080/kafkamessage
.
JSON object is here
{
"message" : "Hello World"
}
When I sent a request, it throws an error shown below.
"message": "Send failed; nested exception is org.apache.kafka.common.errors.TimeoutException: Topic k-topic not present in metadata after 60000 ms."
Expect for this, I defined an auto-created topic but the consumer and producer couldn't produce the topic in the console
[Consumer clientId=consumer-k-group-1, groupId=k-group] Error while fetching metadata with correlation id 728 : {k-topic=LEADER_NOT_AVAILABLE}
[Producer clientId=producer-1] Error while fetching metadata with correlation id 681 : {k-topic=LEADER_NOT_AVAILABLE}
Here is my error
Here is the link: https://github.com/Rapter1990/springbootkafka
How can I fix the issue?