zookeeper+kafka的简单使用
2019-01-22 本文已影响44人
蛋皮皮652
1.首先点击开启zookeeper服务

2. 输入.\bin\windows\kafka-server-start.bat .\config\server.properties命令来开启kafka服务

3.输入 kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic wuyue001命令创建wuyue001的topic

4.创建生产者
kafka-console-producer.bat --broker-list localhost:9092 --topic wuyue001

此窗口不要关闭
5.创建消费者
kafka-console-consumer.bat --zookeeper localhost:2181 --topic wuyue001

6.在生产者端输入任意队列即可进行通讯


spring boot集成kafka
首先添加pom.xml的kafka的依赖
<!--kafka的依赖包-->
<groupId>org.springframework.kafka
<artifactId>spring-kafka
</dependency>

在dev的配置文件夹下写如下配置,我用的是本地的zookeeper和kafka

新建一个kafka的专属文件夹,分别建立生产者,消费者的配置文件和一个监听类

生产者配置文件

消费者配置文件






下载源码demo
下载demo 提取码:ew38