1.配置pom包
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
2.配置application.yml kafka部分:
kafka: # 指定kafka 代理地址,可以多个
bootstrap-servers: hadoop:9092, slave1:9092
template: # 指定默认topic id
default-topic: producer
listener: # 指定listener 容器中的线程数,用于提高并发量
concurrency: 5
consumer:
group-id: myGroup # 指定默认消费者group id
client-id: 200
max-poll-records: 200
auto-offset-reset: earliest # 最早未被消费的offset
producer:
batch-size: 10 # 每次批量发送消息的数量
retries: 3
client-id: 200
3.定义生产者类:

4.定义消费者类:

5.定义生产者controller:

网友评论