以下是在Linux上使用Kafka消息隊列的步驟:
sudo apt update
和sudo apt install openjdk-11-jdk
,CentOS/RHEL系統用sudo yum install java-11-openjdk-devel
,安裝后用java -version
驗證。wget https://downloads.apache.org/kafka/3.5.0/kafka_2.13-3.5.0.tgz
,然后解壓,tar -xzf kafka_2.13-3.5.0.tgz
。config/server.properties
,設置broker.id
、listeners
、log.dirs
、zookeeper.connect
等參數。config/zookeeper.properties
和config/server.properties
。bin/zookeeper-server-start.sh config/zookeeper.properties
,再啟動Kafka,bin/kafka-server-start.sh config/server.properties
。bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
命令創建。bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092
,在新終端啟動消費者bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092
。