Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.
The framework provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions.
Spring Cloud Stream函数式编程模型 是一个用于构建消息驱动微服务应用的框架。
该应用程序通过在代码中建立目标(destination)之间的绑定与外部代理(brokers)进行通信。底层逻辑由特定的Binder实现处理。
总之,有标准的API,可以集成不同的MQ,更换 Binder 实现,可无缝切换中间件。
一、生产者-out
1. 引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
可换:
<!-- 核心 Stream -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<!-- 多个 Binder -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
2. 配置文件
server:
port=8070
spring:
rabbitmq:
host: 192.168.31.231
port: 5672
usernam: admin
password: admin
spring:
cloud:
stream:
bindings:
# 生产者配置 - 很简单
seckillOrder-out-0:
destination: seckill-order-topic # 只指定发送到哪个Exchange
notification-out-0:
destination: user-notification-topic
3. StreamBridge:动态发送消息到指定目标
@Service

最低0.47元/天 解锁文章
952

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



