第十章 消息驱动的微服务: Spring Cloud Stream
Spring Cloud Stream 是一个用来为微服务应用构建消息驱动能力的框架。 它可以基于Spring Boot 来创建独立的、 可用于生产的 Spring 应用程序。 它通过使用 Spring Integration 来连接消息代理中间件以实现消息事件驱动。 Spring Cloud Stream 为一些供应商的消息中间件产品提供了个性化的自动化配置实现,并且引入了发布-订阅、 消费组以及分区这三个核心概念。 简单地说, Spring Cloud Stream 本质上就是整合了 Spring Boot 和 SpringIntegration, 实现了一套轻量级的消息驱动的微服务框架。到目前为止,SpringCloud Stream 只支持下面两个著名的消息中间件的自动化配置:
- RabbitMQ
- Kafka
快速入门
pom.xml 中的依赖关系
<parent>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-parent</artifactid>
<version>l.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
</dependency>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-test</artifactid>
<scope>test</scope>
</dependency>
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-starter-stream-rabbit</artifactid>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-dependencies</artifactid>
<version>Brixton.SRS</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
创建用于接收来自 RabbitMQ 消息的消费者 SinkReceiver
@EnableBinding{Sink.class)
public class SinkReceiver {
private static Logger logger = LoggerFactory. getLogger (HelloApplication. class};
@StreamListener(Sink.INPUT)
public void receive(Object payload) {
logger.info("Received: " + payload);
}
}
第十章 消息驱动的微服务: Spring Cloud Stream的更多相关文章
- SpringCloud---消息驱动的微服务---Spring Cloud Stream
1.概述 1.1 Spring Cloud Stream:用来 为微服务应用 构建 消息驱动能力的框架: 可基于SpringBoot来创建独立.可用于生产的Spring应用程序: 使用Sp ...
- Spring Cloud架构教程 (六)消息驱动的微服务【Dalston版】
Spring Cloud Stream是一个用来为微服务应用构建消息驱动能力的框架.它可以基于Spring Boot来创建独立的.可用于生产的Spring应用程序.它通过使用Spring Integr ...
- spring-cloud-stream消息驱动的微服务
Spring Cloud Stream 是 一 个用来为微服务应用构建消息驱动能力的框架. 它可以基于Spring Boot 来创建独立的. 可用于生产的 Spring 应用程序. 它通过使用 Spr ...
- 微服务 | Spring Cloud(一):从单体SSM 到 Spring Cloud
系列文章目录 微服务 | Spring Cloud(一):从单体SSM 到 Spring Cloud 目录 系列文章目录 前言 单体式架构 微服务架构 优点 缺点 服务发现与弹性扩展 参考 前言 在微 ...
- Spring Cloud架构教程 (七)消息驱动的微服务(核心概念)【Dalston版】
下图是官方文档中对于Spring Cloud Stream应用模型的结构图.从中我们可以看到,Spring Cloud Stream构建的应用程序与消息中间件之间是通过绑定器Binder相关联的,绑定 ...
- Spring Cloud架构教程 (八)消息驱动的微服务(消费组)【Dalston版】
使用消费组实现消息消费的负载均衡 通常在生产环境,我们的每个服务都不会以单节点的方式运行在生产环境,当同一个服务启动多个实例的时候,这些实例都会绑定到同一个消息通道的目标主题(Topic)上. 默认情 ...
- 微服务Spring Cloud与Kubernetes比较
转 http://www.tuicool.com/articles/VnMf2y3 Spring Cloud或Kubernetes都宣称它们是开发运行微服务的最好环境,哪个更好?答案是两个都是,但他们 ...
- 微服务&spring cloud架构系列汇总
为了方便查找,把微服务&微服务架构之spring cloud架构系列文章按时间正序整理了一下,记录如下: 1. 微服务架构之spring cloud 介绍 2. 微服务架构之spring ...
- 使用 Spring Cloud Stream 构建消息驱动微服务
相关源码: spring cloud demo 微服务的目的: 松耦合 事件驱动的优势:高度解耦 Spring Cloud Stream 的几个概念 Spring Cloud Stream is a ...
随机推荐
- Suffix(hash+lcp+二分)
题目链接: Suffix Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of th ...
- wordpress 生成自定义 meta box
工具 https://jeremyhixon.com/tool/wordpress-meta-box-generator/ 使用 生成代码 /** * Generated by the WordPre ...
- Echart--百度地图(散点图)
参考:http://blog.csdn.net/xieweikun7/article/details/52766676 1.首先,下载嘛 Echarts http://echarts.baidu.co ...
- Swift UITextField各种属性的设置
//MARK: 文本输入框 func _initTextField() { //如果需要在模拟器中调用电脑的键盘 快捷键:command + shift + k let textField = UIT ...
- MVC MVVM和传统三层的理解
才学疏浅,请勿喷,如果有理解不对的地方请留言 其实,每个小小的程序员都有个毛病,就是反复写一个东西会觉得这个东西没有新意. 就像让你写三层,你却还是觉得想写MVC模式. 软件小公司做B/S的大部分还是 ...
- BZOJ4837:[Lydsy1704月赛]LRU算法(双指针&模拟)
Description 小Q同学在学习操作系统中内存管理的一种页面置换算法,LRU(LeastRecentlyUsed)算法. 为了帮助小Q同学理解这种算法,你需要在这道题中实现这种算法,接下来简要地 ...
- BZOJ3930 [CQOI2015]选数【莫比乌斯反演】
Description 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案.小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都求一次最大公 ...
- python 抓取网页一部分
import re import requests from bs4 import BeautifulSoup response = requests.get("https://jecvay ...
- 船长带你看书——《selenium2 python 自动化测试实战》(1)
有很多selenium的教程,你没有从头看,当你看的时候已经很难跟上作者的节奏了.现在,你有机会再从头学一次了.从今天开始,船长会从最基本的知识开始,和大家一起学selenium.能不能跟着一起就看大 ...
- ubuntu qq安装
安装最新版qq2016 qq2012下载链接: https://pan.baidu.com/s/1miFVc04 密码: 3g9w 先解压到自己所在的目录,解压命令自己百度在这个目录下,有三个解压包, ...