Spring Cloud Stream 消息消费与分布式缓存实践
1. 许可服务中的消息消费者编写
组织服务每次更改组织数据时,都会向 Kafka 发布消息。现在我们将让许可服务消费组织服务发布的消息。
首先,需要在许可服务的 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>
然后,使用 @EnableBinding
注解许可服务的引导类( licensing-service/src/main/java/com/thoughtmechanix/licenses/Application.java
),并传递 Sink.class
作为参数: