Reputation: 2701
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?
Upvotes: 0
Views: 956
Reputation: 191681
docker run --rm --name zookeeper -p 2181:2181 jplock/zookeeper
(Where your error is)
docker run --rm -p 9092:9092 -e KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 --link zookeeper:zookeeper ches/kafka
Note:
ches/kafka
has had no modifications since 2017 and is not maintained with latest improvments in Kafka
mvn clean package
java -jar ./target/springbootkafka-0.0.1-SNAPSHOT.jar
curl -X POST -H 'Content-Type: application/json' --data '{"message" : "Hello World"}' localhost:8080/kafkamessage
The producer worked, and so does a consumer
$ kafkacat -C -t k-topic -b localhost:9092 -o beginning
{"message":"Hello World","id":"ef0e7883-640c-473b-9b3d-7919d59594a1","messageDate":[2021,2,11,13,10,30,11737000]}
Upvotes: 1