grpc断路器之sentinel 荐
背景
为了防止下游服务雪崩,这里考虑使用断路器
技术选型
由于是springboot服务且集成了istio,这里考虑三种方案
- istio
- hystrix
- sentinel
这里分别有这几种方案的对比
首先考虑的是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 {
@Bean
public ClientInterceptor sentinelGrpcClientInterceptor(){
return new SentinelGrpcClientInterceptor();
}
@Bean
public GlobalClientInterceptorConfigurer globalInterceptorConfigurerAdapter(ClientInterceptor sentinelGrpcClientInterceptor) {
return registry -> registry.addClientInterceptors(sentinelGrpcClientInterceptor);
}
}
方案二:调用时增加拦截器
当然这里也可以换一种方式增加拦截器,如下,在启动类中增加
@Bean
public ClientInterceptor sentinelGrpcClientInterceptor(){
return new SentinelGrpcClientInterceptor();
}
然后在调用类中增加依赖
@Autowired
private 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: 8719
dashboard: localhost:7080
4、部署sentinel dashboard
部署参考下面链接:
启动后访问下相关链接,grpc自动集成上去了,效果如下:
详细配置可以参考官方wiki:https://github.com/alibaba/Sentinel/wiki/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8
grpc断路器之sentinel 荐的更多相关文章
- SpringCloud 断路器之Hystrix
Hystrix-断路器 在分布式环境中,许多服务依赖项中的一些必然会失败.Hystrix是一个库,通过添加延迟容忍和容错逻辑,帮助你控制这些分布式服务之间的交互.Hystrix通过隔离服务之间的访问点 ...
- 5w 字 | 172 图 | 超级赛亚级 Spring Cloud 实战
一.PassJava 项目简介 PassJava-Learning 项目是 PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. PassJava 是一款 Java 面试刷题 的 ...
- 微服务架构 | 5.4 Sentinel 流控、统计和熔断的源码分析
目录 前言 1. Sentinel 的自动装配 1.2 依赖引入 1.3 SentinelWebAutoConfiguration 配置类 1.4 CommonFilter 过滤器 1.5 小结 2. ...
- Sentinel介绍与使用 收藏起来
点赞再看,养成习惯,微信搜索[牧小农]关注我获取更多资讯,风里雨里,小农等你,很高兴能够成为你的朋友. 项目源码地址:公众号回复 sentinel,即可免费获取源码 前言 在家休息的的时候,突然小勇打 ...
- Sentinel 介绍与下载使用
sentinel 前方参考 计算QPS-Sentinel限流算法 https://www.cnblogs.com/yizhiamumu/p/16819497.html Sentinel 介绍与下载使用 ...
- alibaba/Sentinel 分布式 系统流量防卫兵
Sentinel: 分布式系统的流量防卫兵 Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多 ...
- Sentinel限流示例:编码和注解限流
一.Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度保护服务的稳定性. Sentine ...
- Spring Cloud Alibaba | Sentinel: 分布式系统的流量防卫兵初探
目录 Spring Cloud Alibaba | Sentinel: 分布式系统的流量防卫兵初探 1. Sentinel 是什么? 2. Sentinel 的特征: 3. Sentinel 的开源生 ...
- Spring Cloud Alibaba | Sentinel: 服务限流基础篇
目录 Spring Cloud Alibaba | Sentinel: 服务限流基础篇 1. 简介 2. 定义资源 2.1 主流框架的默认适配 2.2 抛出异常的方式定义资源 2.3 返回布尔值方式定 ...
- 限流降级神器,带你解读阿里巴巴开源 Sentinel 实现原理
Sentinel 是阿里中间件团队开源的,面向分布式服务架构的轻量级高可用流量控制组件,主要以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度来帮助用户保护服务的稳定性. 大家可能会问:Se ...
随机推荐
- Docker安装mysql配置my.cnf并挂载到外部机器
1.环境准备,创建外部挂载文件夹conf,data,log mkdir -p /data/dockerdata/mysql3306/{conf,data,log} 2.在/data/dockerdat ...
- ClickHouse介绍(三)MergeTree系列表引擎
MergeTree系列表引擎 ClickHouse中最核心的引擎当属MergeTree系列引擎,其中基础表引擎为MergeTree,常用的表引擎还有ReplacingMergeTree.Summing ...
- 高通Android分区表详解
高通Android分区表详解 Label Purpose of this partition Modem Partition for modem Fsc Cookie partition to sto ...
- Freertos学习:00-介绍
--- title: rtos-freertos-000-介绍 EntryName: rtos-freertos-00-about date: 2020-06-09 23:21:44 categori ...
- python基础-列表list [ ]
列表的定义和操作 列表的特性: 元素数量 支持多个 元素类型 任意 下标索引 支持 重复元素 支持 可修改性 支持 数据有序 是 使用场景 可修改.可重复的 一批数据记录场景 # 定义一个列表list ...
- uniapp+thinkphp5实现微信扫码支付(APP支付)
前言 统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返回预支付订单号的接口,目前微信支付所有场景均使用这一接口.下面介绍的是其中APP的支付的配置与实现流程 配置 1.首先登录 ...
- Docker部署php运行环境
编写docker-compose.yml配置文件,使用nginx作为web服务器,转发php的请求. version: "3" services: web: image: ngin ...
- Linux-makefile命令后面的-j4 -j8是什么意思?
其实是指在编译指定的文件时用多少个线程进行编程的意思~ 相关命令示例如下: make zImage -j8 make modules -j8 --------------------------- m ...
- npm ERR! `perfix` is not a valid npm option
全局路径cmd命令:npm config set perfix "D:\Program Files\nodejs\node_global" 缓存路径cmd命令:npm config ...
- SQL Server 验证某栏位是否存在某字符串(CHARINDEX)
SELECT * FROM LiuJun_PKqitchqi WHERE CHARINDEX('230527Z3258',qr_code) > 0