grpc断路器之sentinel
背景
为了防止下游服务雪崩,这里考虑使用断路器
技术选型
由于是springboot服务且集成了istio,这里考虑三种方案
- istio
- hystrix
- sentinel
这里分别有这几种方案的对比
微服务断路器模式实现:Istio vs Hystrix
Sentinel 与 Hystrix 的对比
首先考虑的是istio,但是在使用istio进行熔断、分流时,流量不稳定,并且返回状态以及数据达不到预取效果,后面考虑到sentinel自动集成了grpc,所以这里使用sentinel。
步骤
1、增加相关依赖
<dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-grpc-adapter</artifactId><version>1.7.1</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.0.1.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
2、增加配置类
方案一:增加全局拦截器
/*** @Auther: lipeng* @Date: 2020/3/23 17:24* @Description:*/
@Order(Ordered.LOWEST_PRECEDENCE)
@Configuration
@Slf4j
public class SentinelConfig {@Beanpublic ClientInterceptor sentinelGrpcClientInterceptor(){return new SentinelGrpcClientInterceptor();}@Beanpublic GlobalClientInterceptorConfigurer globalInterceptorConfigurerAdapter(ClientInterceptor sentinelGrpcClientInterceptor) {return registry -> registry.addClientInterceptors(sentinelGrpcClientInterceptor);}
}
方案二:调用时增加拦截器
当然这里也可以换一种方式增加拦截器,如下,在启动类中增加
@Beanpublic ClientInterceptor sentinelGrpcClientInterceptor(){return new SentinelGrpcClientInterceptor();}
然后在调用类中增加依赖
@Autowiredprivate ClientInterceptor sentinelGrpcClientInterceptor;public void doXXX(){XXXGrpc.XXXBlockingStub stub = XXXGrpc.newBlockingStub(serverChannel).withInterceptors(sentinelGrpcClientInterceptor);XXXApi.XXXResponse response = stub.withDeadlineAfter(grpcTimeout, TimeUnit.MILLISECONDS).doXXX(request);}
3、增加sentinel dashboard配置
spring:cloud:sentinel:transport:port: 8719dashboard: localhost:7080
4、部署sentinel dashboard
部署参考下面链接:
Sentinel 控制台
启动后访问下相关链接,grpc自动集成上去了,效果如下:
详细配置可以参考官方wiki:https://github.com/alibaba/Sentinel/wiki/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8
grpc断路器之sentinel相关推荐
- Spring Cloud Alibaba 微服务详细笔记
文章目录 SpringCloud 一.微服务概述 1.1.什么是微服务? 1.2.为什么是微服务? 1.3.架构演变 1.4.微服务的解决方案 二.什么是SpringCloud 2.1.官方定义 2. ...
- Spring Cloud 阿里哨兵
Spring Cloud 阿里哨兵 哨兵简介 随着微服务的普及,服务调用的稳定性变得越来越重要.Sentinel以"流量"为切入点,在流量控制.断路.负载保护等多个领域开展业务,保 ...
- Spring Cloud Alibaba 参考文档-2021.0.4.0
Spring Cloud Alibaba 简介 依赖管理 Spring Cloud Alibaba Nacos Discovery 3.1 服务注册/发现:Nacos Discovery 3.2 如何 ...
- SpringCloud Alibaba 简介
概述 Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发 ...
- 【Android】JNI调用(完整版)
原文出处:http://blog.csdn.net/kangyaping/article/details/6584027#t0 Chap1:JNI完全手册... 3 Chap2:JNI-百度百科... ...
- springCloud sentinel 流量卫兵
什么是sentinel 0.说明 https://spring-cloud-alibaba-group.github.io/github-pages/hoxton/en-us/index.html#_ ...
- springcloud-alibaba-sentinel(1)sentinel流量卫兵介绍
文章目录 前言 (1)什么是sentinel (2)sentinel的历史 (3)sentinel的特性 (4)核心概念 资源 规则 (5)sentinel的生态景观 (6)sentinel组成 前言 ...
- sentinel初探
背景: 最近线上系统遇到线程耗尽,导致不能正常办理业务问题.通过分析发现,因为其中两个定时任务触发时间短,每个处理耗时反而很长,线程耗尽,已获的线程部分报没有提供者,即服务不可用,同时导致部分业务请求 ...
- Sentinel介绍与使用 收藏起来
点赞再看,养成习惯,微信搜索[牧小农]关注我获取更多资讯,风里雨里,小农等你,很高兴能够成为你的朋友. 项目源码地址:公众号回复 sentinel,即可免费获取源码 前言 在家休息的的时候,突然小勇打 ...
最新文章
- iframe中的奇怪现象
- thinkphp无法加载模块解决办法
- 安卓APP_ Fragment(2)—— Activity与Fragment的通信
- 14.1178亿人 流动人口超3亿 “大国普查”这些数据很重要
- Python抓取单个网页中所有的PDF文档
- recv返回的数据过大 易语言_高性能数据传输系统的框架设计
- python读mat文件_我用Python对咪蒙的1013篇历史文章做了一次深度的数据分析...
- iOS获取手机卡IMSI信息
- 山东烟建借沟通CTBS实现财务数据大集中
- QCC3005芯片 Line IN 听歌的时候声音比较小
- 「Python海龟画图」利用海龟画笔绘制奥运五环
- How do I find the FC ID (WWN) of a scsi device/LUN on Red Hat Enterprise Linux?
- 谷歌雅虎将联手实行即时信息兼容性计划
- 华为交换机配置ntp服务时间 自动同步不成功unsynchronized
- libuv之msys2环境下编译
- html表单 多行输入文字,如何在HTML中创建多行文本输入(文本区域)?
- c#web网页连接数据库产品出库入库数据更新
- 永恒之塔修改服务器名字,永恒之塔修改称号提升人物各种属性教程
- 我是一只程序猿,沪漂一整年。
- 07 - Nor Flash