-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun.sh
executable file
·64 lines (53 loc) · 1.76 KB
/
run.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -Eeuo pipefail
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
help_and_exit () {
echo "USAGE: $0 zookeeper|kafka|topic|producer|consumer|offsets"
exit 1
}
cd "$script_dir" || help_and_exit
if [ "$#" -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
help_and_exit
fi
action="$1"
kafka_dir="$script_dir/kafka"
if [ ! -d "$kafka_dir" ]; then
echo "Downloading kafka..."
git clone [email protected]:apache/kafka.git "$kafka_dir"
echo "Building kafka..."
cd "$kafka_dir" || help_and_exit
./gradlew jar -PscalaVersion=2.13.6
fi
zookeeper_config="$kafka_dir/config/zookeeper.properties"
kafka_config="$kafka_dir/config/server.properties"
kafka_endpoint="${KAFKA_ENDPOINT:-localhost:9092}"
topic_name="${KAFKA_TOPIC:-topic}"
case "$action" in
consumer)
cd "$kafka_dir/bin" || help_and_exit
./kafka-console-consumer.sh --topic "$topic_name" --from-beginning --bootstrap-server "$kafka_endpoint"
;;
kafka)
cd "$kafka_dir/bin" || help_and_exit
./kafka-server-start.sh "$kafka_config"
;;
producer)
cd "$kafka_dir/bin" || help_and_exit
./kafka-console-producer.sh --topic "$topic_name" --bootstrap-server "$kafka_endpoint"
;;
topic)
cd "$kafka_dir/bin" || help_and_exit
./kafka-topics.sh --create --topic "$topic_name" --bootstrap-server "$kafka_endpoint" --partitions 1 --replication-factor 1
;;
zookeeper)
cd "$kafka_dir/bin" || help_and_exit
./zookeeper-server-start.sh "$zookeeper_config"
;;
offsets)
cd "$kafka_dir/bin" || help_and_exit
./kafka-run-class.sh kafka.tools.GetOffsetShell --topic "$topic_name" --bootstrap-server "$kafka_endpoint"
;;
*)
help_and_exit
;;
esac