E-commerce application developed while studying Kafka (Alura)
sudo apt update
sudo apt upgrade
sudo apt install openjdk-11-jdk
wget https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz
tar -xzvf kafka_2.13-3.4.0.tgz
cd kafka_2.13-3.4.0/
ip addr | grep "eth0" | grep -oEi '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1
Note: Replace the retrieved IP above
vi config/server.properties
Add the following line:
advertised.listeners=PLAINTEXT://172.x.y.z:9092
In an administrator terminal
netsh interface portproxy add v4tov4 listenport=9092 listenaddress=0.0.0.0 connectport=9092 connectaddress=172.x.y.z
By default, all Kafka runtime data is saved in the system's temporary directory (e.g., /tmp/
) and can be lost at any time. To resolve this, we can create and configure a new directory within the Kafka folder itself.
First, create the new directories:
mkdir -p data/kafka data/zookeeper
Open the Kafka configuration file and edit the value of log.dirs
to point to <...>/data/kafka
:
vi config/server.properties
Open the Zookeeper configuration file and edit the value of dataDir
to point to <...>/data/zookeeper
:
vi config/zookeeper.properties
First, start Zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
Then, in another terminal:
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic LOJA_NOVO_PEDIDO
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
bin/kafka-topics.sh --describe --bootstrap-server localhost:9092
Note: Each input line enqueues a new message
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic LOJA_NOVO_PEDIDO
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic LOJA_NOVO_PEDIDO # --from-beginning
bin/kafka-consumer-groups.sh --all-groups --bootstrap-server localhost:9092 --describe
bin/kafka-topics.sh --alter --bootstrap-server localhost:9092 --topic ECOMMERCE_NEW_ORDER --partitions 3