Spring Cloud Alibaba学习笔记(13) - Spring Cloud Stream的监控与异常处理
Spring Cloud Stream监控
Spring Boot Actuator组件用于暴露监控端点,很多监控工具都需要依赖该组件的监控端点实现监控。而项目集成了Stream及Actuator后也会暴露相应的监控端点.
首先需要在项目里集成Actuator,添加依赖如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
添加配置,暴露所有监控端点,并显示健康检测详情
management:
endpoint:
health:
# 显示健康检测详情
show-details: always
endpoints:
web:
exposure:
# 暴露所有监控端点
include: '*'
访问http://localhost:端口号/actuator可以获取所有暴露出来的监控端点,Stream的相关监控端点也在其中

/actuator/bindings端点可以用于查看bindings相关信息:

/actuator/channels端点用于查看channels的相关信息,“input”和“output”就是channel,可以认为这些channel是topic的抽象:

/actuator/health端点中可以查看binder及RocketMQ的状态,主要是用于查看MQ的连接情况,如果连接不上其status则为DOWN:

Spring Cloud Stream异常处理
局部处理
配置文件
spring:
cloud:
stream:
bindings:
input:
destination: test-destination
group: test-group
output:
destination: test-destination
代码实现
@Slf4j
@SpringBootApplication
@EnableBinding({Processor.class})
@EnableScheduling
public class Study01Application {
public static void main(String[] args) {
SpringApplication.run(Study01Application.class, args);
}
@StreamListener(value = Processor.INPUT)
public void handle(String body) {
throw new RuntimeException("运行时错误");
}
@ServiceActivator(inputChannel = "test-destination.test-group.errors")
public void handleError(ErrorMessage message) {
Throwable throwable = message.getPayload();
log.error("截获异常", throwable);
Message<?> originalMessage = message.getOriginalMessage();
assert originalMessage != null;
log.info("原始消息体 = {}", new String((byte[]) originalMessage.getPayload()));
}
@Bean
@InboundChannelAdapter(value = Processor.OUTPUT, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource<String> test() {
return () -> new GenericMessage<>("qwer");
}
}
全局处理
代码实现
@StreamListener(value = Processor.INPUT)
public void handle(String body) {
throw new RuntimeException("运行时错误");
}
@StreamListener("errorChannel")
public void error(Message<?> message) {
ErrorMessage errorMessage = (ErrorMessage) message;
log.warn("Handling ERROR = {} " + errorMessage);
}
Spring Cloud Alibaba学习笔记(13) - Spring Cloud Stream的监控与异常处理的更多相关文章
- Spring 源码学习笔记10——Spring AOP
Spring 源码学习笔记10--Spring AOP 参考书籍<Spring技术内幕>Spring AOP的实现章节 书有点老,但是里面一些概念还是总结比较到位 源码基于Spring-a ...
- Spring 源码学习笔记11——Spring事务
Spring 源码学习笔记11--Spring事务 Spring事务是基于Spring Aop的扩展 AOP的知识参见<Spring 源码学习笔记10--Spring AOP> 图片参考了 ...
- Spring Cloud Alibaba学习笔记(1) - 整合Spring Cloud Alibaba
Spring Cloud Alibaba从孵化器版本毕业:https://github.com/alibaba/spring-cloud-alibaba,记录一下自己学习Spring Cloud Al ...
- Spring Cloud Alibaba学习笔记(15) - 整合Spring Cloud Gateway
Spring Cloud Gateway 概述 Spring Cloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于Netty.Reactor以及WEbFlux构建,它 ...
- Spring Cloud Alibaba学习笔记(3) - Ribbon
1.手写一个客户端负载均衡器 在了解什么是Ribbon之前,首先通过代码的方式手写一个负载均衡器 RestTemplate restTemplate = new RestTemplate(); // ...
- Spring Cloud Alibaba学习笔记(22) - Nacos配置管理
目前业界流行的统一配置管理中心组件有Spring Cloud Config.Spring Cloud Alibaba的Nacos及携程开源的Apollo,本文将介绍Nacos作为统一配置管理中心的使用 ...
- Spring Cloud Alibaba学习笔记(7) - Sentinel规则持久化及生产环境使用
Sentinel 控制台 需要具备下面几个特性: 规则管理及推送,集中管理和推送规则.sentinel-core 提供 API 和扩展接口来接收信息.开发者需要根据自己的环境,选取一个可靠的推送规则方 ...
- Spring Cloud Alibaba学习笔记(2) - Nacos服务发现
1.什么是Nacos Nacos的官网对这一问题进行了详细的介绍,通俗的来说: Nacos是一个服务发现组件,同时也是一个配置服务器,它解决了两个问题: 1.服务A如何发现服务B 2.管理微服务的配置 ...
- Spring Cloud Alibaba学习笔记
引自B站楠哥:https://space.bilibili.com/434617924 一.创建父工程 创建父工程hello-spring-cloud-alibaba Spring Cloud Ali ...
- Spring Cloud Alibaba学习笔记(20) - Spring Cloud Gateway 内置的全局过滤器
参考:https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#_global_filter ...
随机推荐
- vim支持golang函数调整
golang函数跳转需要借助godef实现 godef安装如下 go get -v github.com/rogpeppe/godef go install -v github.com/rogpepp ...
- c代码审查软件
1. Coccinelle http://coccinelle.lip6.fr/
- 海思 Hi3516A Hi3518E V200 芯片介绍
海康是生产监控摄像头和硬盘录像机的,海思是提供机器里芯片的,海思属于华为的. http://www.hisilicon.com/en/Products/ProductList/Surveillance ...
- 方法不会等待Task执行完才返回数据
- openresty开发系列15--lua基础语法4表table和运算符
openresty开发系列15--lua基础语法4表table和运算符 lua中的表table 一)table (表)Table 类型实现了一种抽象的"关联数组".即可用作数组,也 ...
- ASP中如何将数据库内容导入到数组?并进行字符串对比
dim Arr sql1="select id from [aaa] where reader not like '%"&userid&"%'" ...
- 安装DEDECMS出现Function ereg_replace()错误的解决方法
这个问题我记得以前有遇到的,是在本地调试dedecms整站程序的时候,从网上下载了一个整套程序包括模板到本地调试,导入数据库安装都正常,但是登陆 后台就出现"Deprecated: Func ...
- osg编译日志-release
1>------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------1> Checking Build System1> CMake does ...
- 定时备份删除数据库sql
1.备份数据库 mkdir -p /home/mysql/mysql_bak/ vi mysql_bak.sh #!/bin/bash #Shell Command For Backup MySQL ...
- 123457123456#1#----com.MC.CarWashKidsGames234----前拼后广--洗车游戏mc-mc1111
com.MC.CarWashKidsGames234----前拼后广--洗车游戏mc-mc1111