好了,下面我们开始整合:
首先,先往pom.xml文件添加Kafka的依赖,
org.springframework.kafka
spring-kafka
2.2.0.RELEASE
org.springframework.kafka
spring-kafka-test
test
然后,接下来是配置文件(以下提供properties格式,yml格式 ,供大家随便自取),
当然注释也是要好好看看的,毕竟都一字字敲的。
application.properties
#============== kafka ===================
指定kafka 代理地址,可以多个
#spring.kafka.bootstrap-servers=123.xxx.x.xxx:19092,123.xxx.x.xxx:19093,123.xxx.x.xxx:19094
spring.kafka.bootstrap-servers=192.168.x.xxx:9092
#=============== producer生产者 =======================
spring.kafka.producer.retries=0
每次批量发送消息的数量
spring.kafka.producer.batch-size=16384
缓存容量
spring.kafka.producer.buffer-memory=33554432
指定消息key和消息体的编解码方式
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
#=============== consumer消费者 =============&#