1、启动Kafka
bin/kafka-server-start.sh config/server.properties &
2、停止Kafka
bin/kafka-server-stop.sh
3、创建Topic
bin/kafka-topics.sh –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic jiangzh-topic
4、查看已经创建的Topic信息
bin/kafka-topics.sh –list –zookeeper localhost:2181
5、发送消息
bin/kafka-console-producer.sh –broker-list 192.168.220.128:9092 –topic jiangzh-topic
6、接收消息
bin/kafka-console-consumer.sh –bootstrap-server 192.168.220.128:9092 –topic jiangzh-topic –from-beginning
bin/kafka-topics.sh –zookeeper localhost:2181 –create –topic heima –partitions 2 –replicationfactor 1
–zookeeper:指定了Kafka所连接的Zookeeper服务地址
–topic:指定了所要创建主题的名称
–partitions:指定了分区个数
–replication-factor:指定了副本因子
–create:创建主题的动作指令
展示所有主题
bin/kafka-topics.sh –zookeeper localhost:2181 –list
查看主题详情
bin/kafka-topics.sh –zookeeper localhost:2181 –describe –topic heima
–describe 查看详情动作指令
启动消费端接收消息
bin/kafka-console-consumer.sh –bootstrap-server localhost:9092 –topic heima
–bootstrap-server 指定了连接Kafka集群的地址
生产端发送消息
bin/kafka-console-producer.sh –broker-list localhost:9092 –topic heima
–broker-list 指定了连接的Kafka集群的地址