Steps to create a topic using Kafka commands
zookeeper-server-start.sh config/zookeeper.properties kafka-server-start.sh config/server.properties
kafka-topics.sh --create --topic my-topic --partitions 3 --replication-factor 1
kafka-topics.sh --list
kafka-console-producer.sh --topic my-topic --message "Hello, world!"
kafka-console-consumer.sh --topic my-topic --from-beginning
Specific code example
# 启动ZooKeeper服务 zookeeper-server-start.sh config/zookeeper.properties # 启动Kafka服务 kafka-server-start.sh config/server.properties # 创建主题 kafka-topics.sh --create --topic my-topic --partitions 3 --replication-factor 1 # 查看主题 kafka-topics.sh --list # 向主题发送消息 kafka-console-producer.sh --topic my-topic --message "Hello, world!" # 从主题消费消息 kafka-console-consumer.sh --topic my-topic --from-beginning
Note
The above is the detailed content of Steps to create a Kafka topic: Using Kafka commands. For more information, please follow other related articles on the PHP Chinese website!