Spring-Cloud-Stream(消息代理门面)

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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值