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 ...
随机推荐
- MySQL not equal to operator <> && !=
MySQL :: MySQL 5.7 Reference Manual :: 12.3.2 Comparison Functions and Operatorshttps://dev.mysql.co ...
- [Eclipse]已经写好的代码怎样切换为unix下的换行符?
问题:使用eclise提交文件到github,每行文件后面都有^M字符 切换换行符的显示格式, 但是这样只能对新文件起作用,修改旧文件:
- scipy.fftpack fft
from scipy.fftpack import fft SciPy提供fftpack模块,可让用户计算快速傅立叶变换 例子: >>> a = np.arange(1,5) > ...
- django实战总结2
https://www.jianshu.com/p/9b3bfe934511 https://www.cnblogs.com/1Q84mi/p/xadmin002.html https://blog. ...
- Spring mvc4 + ActiveMQ 整合【什么框架与什么框架的整合搜索】
一.配置部分 二.代码部分 三.页面部分 四.Controller控制器 五.效果展示 六.加入监听器 七.最最重要的,别忘了打赏 一.配置部分 ActiveMQ的安装这就不说了,很简单, 这个例子采 ...
- LeetCode_344. Reverse String
344. Reverse String Easy Write a function that reverses a string. The input string is given as an ar ...
- 线性回归:鸢尾花数据iris
# encoding: utf-8 from sklearn.linear_model import LogisticRegression import numpy as np from sklear ...
- git 打tag(版本)、推送代码
服务端:192.168.0.96 gitlab 客户端:192.168.0.97 git 服务端gitlab安装请参照: https://www.cnblogs.com/effortsing/p/10 ...
- Mathjax与LaTex公式简介
MathJax与LaTex公式简介 (转载) PS: 原文链接写的非常好!!! 博主写这篇文章,一是为了防止原链接失效,二是在cnblogs上测试MathJax; 本文从math.stackexcha ...
- Data - 深入浅出学统计 - 下篇
本文是已读书籍的内容摘要,少部分有轻微改动,但不影响原文表达. :以漫画形式来讲解最基本的统计概念和方法. ISBN: 9787121299636 https://book.douban.com/su ...