Kafka "TimeoutException: Topic not present in metadata" in CI
The producer blocked waiting for metadata about a topic and the wait expired. The broker either does not know that topic (it was never created and auto-create is off) or was still starting when the send ran.
What this error means
A send fails with "org.apache.kafka.common.errors.TimeoutException: Topic orders not present in metadata after 60000 ms." after a long pause.
org.apache.kafka.common.errors.TimeoutException:
Topic orders not present in metadata after 60000 ms.Common causes
The topic does not exist and auto-create is off
With auto-creation disabled, metadata for an uncreated topic never appears, so the producer waits out the full timeout.
The broker was not ready when the producer started
A producer that connects during broker startup cannot fetch metadata until the broker finishes booting.
How to fix it
Create the topic before producing
Create it as a setup step so metadata is available immediately.
kafka-topics.sh --bootstrap-server localhost:9092 \
--create --if-not-exists --topic orders --partitions 1 --replication-factor 1Wait for the broker before the first send
Poll an admin call until the broker answers, then run the producer.
until kafka-topics.sh --bootstrap-server localhost:9092 --list >/dev/null 2>&1; do
echo "waiting for kafka"; sleep 3
doneHow to prevent it
- Create topics explicitly in a setup step before producing.
- Gate the producer on broker readiness.
- Keep the metadata timeout generous for a slow first start.