Spring Cloud Stream消息处理与分布式缓存实践
1. 编写消息消费者
组织服务每次数据变更时会向Kafka发布消息,感兴趣的服务可做出响应,无需组织服务显式调用。下面以许可服务为例,介绍如何使用Spring Cloud Stream消费消息。
- 添加依赖 :在许可服务的 pom.xml 文件中添加Spring Cloud Stream依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
- 配置绑定 :在许可服务的启动类
LicenseServiceApplication上使用@EnableBinding注解绑定到消息代理,由于许可服务是消息消费者,传入Sink.clas
Spring Cloud Stream与Redis缓存实践
超级会员免费看
订阅专栏 解锁全文
1567

被折叠的 条评论
为什么被折叠?



