https://blog.csdn.net/kxj19980524/article/details/90267404
参考上面整合rabbitmq,里面代码不用变,换一下依赖换一下配置文件就可以了,其余的都一样
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
消息发送者,配置文件,集群的话,也指定一个ip端口就可以了,我用的就是集群,指定其中一个主机就可以.
#kafka
spring.cloud.stream.kafka.binder.brokers=192.168.1.20:9092
spring.cloud.stream.kafka.binder.zk-nodes=192.168.1.20:2182
spring.cloud.stream.kafka.binder.auto-add-partitions=true
spring.cloud.stream.kafka.binder.auto-create-topics=true
spring.cloud.stream.kafka.binder.min-partition-count=1
spring.cloud.stream.bindings.member.destination=mytopic
spring.cloud.stream.bindings.member.content-type=text/plain
spring.cloud.stream.bindings.member.producer.partitionCount=1
消息接收者
spring.cloud.stream.kafka.binder.brokers=192.168.1.20:9092
spring.cloud.stream.kafka.binder.zk-nodes=192.168.1.20:2182
spring.cloud.stream.kafka.binder.auto-add-partitions=true
spring.cloud.stream.kafka.binder.auto-create-topics=true
#这个得跟发送消息端的名称一致
spring.cloud.stream.bindings.member.destination=mytopic
#加上就能接收到之前发送没接收到的消息.
spring.cloud.stream.bindings.member.group=s1