kafka_2.13-3.0.0 Quick Start启动

2022年10月24日13:16:53

Apache Kafkakafka_2.13-3.0.0 Quick Start启动https://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  # 错误
  • 作者:CarloPan
  • 原文链接:https://blog.csdn.net/CarloPan/article/details/121536357
    更新时间:2022年10月24日13:16:53 ,共 2175 字。