-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-topics.sh
More file actions
34 lines (28 loc) · 858 Bytes
/
create-topics.sh
File metadata and controls
34 lines (28 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Starts Kafka in the background
/etc/confluent/docker/run &
# Waits for Kafka to start on port 9092
echo "Waiting for Kafka to start..."
MAX_WAIT=60
SLEEP_INTERVAL=3
elapsed=0
while ! nc -z localhost 9092; do
sleep $SLEEP_INTERVAL
elapsed=$((elapsed+SLEEP_INTERVAL))
if [ $elapsed -ge $MAX_WAIT ]; then
echo "Kafka was not ready after $MAX_WAIT seconds."
exit 1
fi
echo "Still waiting for Kafka... ($elapsed seconds)"
done
# Creates the "orders" topic if it does not exist
echo "Kafka is ready. Creating topic 'orders'..."
kafka-topics --bootstrap-server localhost:9092 \
--create --if-not-exists \
--topic orders \
--partitions 1 \
--replication-factor 1
echo "Existing topics:"
kafka-topics --bootstrap-server localhost:9092 --list
# Keeps the container running in the foreground
wait