-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafkaInit.sh
executable file
·79 lines (57 loc) · 1.62 KB
/
kafkaInit.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#set this to whatever in the shell environment
#KAFKA_HOME=....
function start_zookeeper() {
printf "Starting zookeeper ...\n"
$(nohup ${KAFKA_HOME}/bin/zookeeper-server-start.sh -daemon config/zookeeper.properties > /dev/null 2>&1 &)
status=$?
if [[ $status == 0 ]]
then
printf "success! zookeeper started, result = $status\n"
else
printf "failed to start zookeeper ... $status\n"
fi
echo $status
}
function start_kafka() {
printf "Starting kafka ...\n"
$(nohup ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon config/server.properties > /dev/null 2>&1 &)
status=$?
if [[ $status == 0 ]]
then
printf "success! kafka started, result = $status\n"
else
printf "failed to start kafka ... $status\n"
fi
echo $status
}
function create_topics() {
topic_name=$1
result=$(${KAFKA_HOME}/bin/kafka-topics.sh --create \
--topic $topic_name \
--replication-factor 1 \
--partitions 1 \
--bootstrap-server localhost:9092
)
echo $result
}
#start zookeeper first
start_result=$(start_zookeeper)
#start kafka now
if [[ $start_result ]]
then
printf "zookeeper started successfully ,,,\n"
kafka_result=$(start_kafka)
if [[ $kafka_result ]]
then
printf "kafka started successfully ,,,\n"
fi
else
printf "failed to start kafka ... $kafka_result\n"
fi
#create the standard topics
for topic in orderconfirmed-events orderpicked-events enotification-events order-error-events
do
create_topics $topic
done
exit 0