-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_servers.sh
49 lines (34 loc) · 1.04 KB
/
start_servers.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
#!/bin/bash
# Install Maven
sudo apt update
sudo apt install maven
sudo apt install docker-compose
sudo apt install docker
# Change directory to kafkawithzookeeper
cd kafkawithzookeeper || exit
# Start Kafka and Zookeeper containers
docker-compose up -d
# Wait for 5 seconds
sleep 5
# Change directory to kafkaproducer
cd ../kafkaproducer || exit
# Build the producer application
mvn clean install
# Run the producer application
java -jar target/kafkaproducer-0.0.1-SNAPSHOT.jar &
# Change directory to kafkaconsumer
cd ../kafkaconsumer || exit
# Build the consumer application
mvn clean install
# Run the consumer application and tail the logs
java -jar target/kafkaconsumer-0.0.1-SNAPSHOT.jar &
consumer_pid=$!
# Tail the logs of the consumer project
tail -f logs/consumer.log &
# Wait for the user to manually close the servers
read -p "Press any key to stop the servers and containers..."
# Stop the producer and consumer applications
kill "$consumer_pid"
# Stop Kafka and Zookeeper containers
cd ../kafkawithzookeeper || exit
docker-compose down