-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-kafka-environment.sh
executable file
·34 lines (29 loc) · 1.52 KB
/
docker-kafka-environment.sh
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
export BROKER_LIST=$(docker-compose ps -q kafka|xargs docker inspect --format='{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}:{{(index (index .NetworkSettings.Ports "9092/tcp") 0).HostPort}}'|paste -sd "," -)
export ZOOKEEPER=$(docker-compose ps -q zookeeper|xargs docker inspect --format='{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}:{{(index (index .NetworkSettings.Ports "2181/tcp") 0).HostPort}}'|head -n1)
if [ -z "$BROKER_LIST" ]; then
echo ""
echo "Warning! \$BROKER_LIST is empty"
fi
if [ -z "$ZOOKEEPER" ]; then
echo ""
echo "Warning! \$ZOOKEEPER is empty"
fi
if [[ ! -z "$BROKER_LIST" && ! -z "$ZOOKEEPER" ]]; then
echo "Environment variables set:"
echo " \$BROKER_LIST=${BROKER_LIST}"
echo " \$ZOOKEEPER=${ZOOKEEPER}"
echo ""
echo "Now you can use (from this shell) kafka-cli, ie:"
echo " \$KAFKA_HOME/bin/kafka-topics.sh --zookeeper \$ZOOKEEPER --create --replication-factor 1 --partitions 1 --topic test"
echo " \$KAFKA_HOME/bin/kafka-topics.sh --zookeeper \$ZOOKEEPER --list"
echo " \$KAFKA_HOME/bin/kafka-topics.sh --zookeeper \$ZOOKEEPER --describe --topic test"
echo ""
echo " \$KAFKA_HOME/bin/kafka-console-producer.sh --broker-list \$BROKER_LIST --topic test"
echo ""
echo " \$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server \$BROKER_LIST --topic test --from-beginning"
echo ""
echo ""
echo "Fill topic with 10k random strings:"
echo " cat /dev/urandom|base64|nl|head -n 100000|\$KAFKA_HOME/bin/kafka-console-producer.sh --broker-list \$BROKER_LIST --topic test"
echo ""
fi