Apache Kafkahttps://kafka.apache.org/30/documentation/#quickstart
STEP 1: GET KAFKA
Download the latest Kafka release and extract it:
$ tar -xzf kafka_2.13-3.0.0.tgz $ cd kafka_2.13-3.0.0
STEP 2: START THE KAFKA ENVIRONMENT
NOTE: Your local environment must have Java 8+ installed.
Run the following commands in order to start all services in the correct order:
# Start the ZooKeeper service # Note: Soon, ZooKeeper will no longer be required by Apache Kafka. $ bin/zookeeper-server-start.sh config/zookeeper.properties
Open another terminal session and run:
# Start the Kafka broker service $ bin/kafka-server-start.sh config/server.properties
Once all services have successfully launched, you will have a basic Kafka environment running and ready to use.
#可用命令: 创建topic bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 bin/kafka-topics.sh --create --topic kafkaToMysqlTopicTest --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 # 查看topic sh kafka-topics.sh --topic quickstart-events --describe --bootstrap-server 127.0.0.1:9092 bin/kafka-topics.sh --topic quickstart-events --describe --bootstrap-server 127.0.0.1:9092 # 查看topic 列表 [dq@test kafka_2.13-3.0.0]$ bin/kafka-topics.sh --list --bootstrap-server 127.0.0.1:9092 # 查看消费者列表 sh kafka-consumer-groups.sh --list --bootstrap-server 127.0.0.1:9092 bin/kafka-consumer-groups.sh --list --bootstrap-server 127.0.0.1:9092 # 生产消息 bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092 $ bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092 This is my first event This is my second event $ bin/kafka-console-producer.sh --topic test-110701-topic --bootstrap-server localhost:9092 $ bin/kafka-console-producer.sh --topic kafkaToMysqlTopicTest --bootstrap-server localhost:9092 # 消费消息 $ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092 This is my first event This is my second event # 消费消息 $ bin/kafka-console-consumer.sh --topic test-110701-topic --from-beginning --bootstrap-server localhost:9092 $ bin/kafka-console-consumer.sh --topic kafkaToMysqlTopicTest --from-beginning --bootstrap-server localhost:9092 # 从指定位置消费消息 $ bin/kafka-console-consumer.sh --topic quickstart-events --offset 1 --bootstrap-server localhost:9092 # 错误