spring cloud stream 是一个用来为微服务应用构建消息驱动能力的框架,是基于spring boot 来创建独立的、可用于生产的spring应用程序。
1.配置
2.接收消息
1.注解绑定@EnableBinding(Sink.class)
2.注解监听@StreamListener(Sink.INPUT)

3.发送消息(自动发送)
1.注解绑定@EnableBinding(Source.class)
2.注解发送通道@InboundChannelAdapter
poller = @poller(fixedDelay = “1000”,maxMessagesPerPoll = “1”) 每1000毫秒自动发送一次


4.发送和接收绑定
将发送(output)和接收(input)配置为同一个通道,就可以自动接收

5.通过接口发送和接收消息
对象

接口:


发送:receive 方法名是固定的,Message<要传递的对象>

接收

发送通道和接收通道关联(exchange2)

注意:前面写的类MessageReceiver 中的注解@EnableBinding(Sink.class) 需要删掉,因为@StreamListener注解只能在一个地方使用,将@EnableBinding删掉就不会绑定到Spring clould Stream,也就不会去做监听
本文详细介绍了如何利用Spring Cloud Stream在Spring Boot中实现消息驱动的微服务,包括配置、消息接收与发送、绑定与接口操作,以及注意事项。
8万+

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



