以下是在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
。