41.Sentinel
Feign 整合 Sentinel
依赖
<!--Feign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--sentinel-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
application.properties
# Feign 整合 Sentinel
feign.sentinel.enabled=true
UserCenterFeignClient
@FeignClient(
name = "user-center",
// fallback = UserCenterFeignClientFallback.class
fallbackFactory = UserCenterFeignClientFallbackFactory.class
)
public interface UserCenterFeignClient {
@GetMapping("/users/{id}")
UserDTO queryById(@PathVariable("id") Integer id);
}
UserCenterFeignClientFallback
# 注意一定要加@Component
@Component
public class UserCenterFeignClientFallback implements UserCenterFeignClient {
@Override
public UserDTO queryById(Integer id) {
UserDTO userDTO = new UserDTO();
userDTO.setWxNickname("默认用户");
return userDTO;
}
}
UserCenterFeignClientFallbackFactory
@Component
@Slf4j
public class UserCenterFeignClientFallbackFactory implements FallbackFactory<UserCenterFeignClient> {
@Override
public UserCenterFeignClient create(Throwable throwable) {
return new UserCenterFeignClient() {
@Override
public UserDTO queryById(Integer id) {
log.warn("远程调用被限流/降级了", throwable);
UserDTO userDTO = new UserDTO();
userDTO.setWxNickname("默认用户");
return userDTO;
}
};
}
}
FallbackFactory 比 Fallback 更强大,可以打印更多异常信息。
源码:


规则持久化
41.Sentinel的更多相关文章
- Redis 安装,主从配置及Sentinel配置自动Failover
1.安装redis 首页地址:http://redis.io/ 下载地址:http://download.redis.io/ 下载最新的源码包 tar -zxvf redis-stable.tar.g ...
- Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)
Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...
- Redis Sentinel配置小记
Sentinel是一个管理多个redis实例的工具,它可以实现对redis的监控.通知.自动故障转移.sentinel不断的检测redis实例是否可以正常工作,通过API向其他程序报告redis的状态 ...
- Redis哨兵模式(sentinel)部署记录(主从复制、读写分离、主从切换)
部署环境: CentOS7.5 192.168.94.11 (master) 192.168.94.22 (slave0) 192.168.94.33 (slave1) 192.168.94.44 ...
- alibaba/Sentinel 分布式 系统流量防卫兵
Sentinel: 分布式系统的流量防卫兵 Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多 ...
- Redis Sentinel初体验
自Redis增加Sentinel集群工具以来,本博主就从未尝试过使用该工具.最近在调研目前主流的Redis集群部署方案,所以详细地看了一遍官方对于Sentinel的介绍并在自己的台式机上完成了 ...
- Redis主从集群以及Sentinel的配置
安装完redis后,修改几个redis从节点的配置文件redis.conf,主要是加入主节点位置 slaveof 另外需要修改的地方包括,这样允许其他的从节点连入 bind 0.0.0.0 prote ...
- Redis(十五):哨兵Sentinel
Redis哨兵 Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你 ...
- Sentinel限流示例:编码和注解限流
一.Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度保护服务的稳定性. Sentine ...
- redis复制集(sentinel)
https://www.jianshu.com/p/45ffd2a84143 内核配置 cat >> /etc/rc.local << EOF echo never > ...
随机推荐
- 从面试题入手,畅谈 Vue 3 性能优化
前言 今年又是一个非常寒冷的冬天,很多公司都开始人员精简.市场从来不缺前端,但对高级前端的需求还是特别强烈的.一些大厂的面试官为了区分候选人对前端领域能力的深度,经常会在面试过程中考察一些前端框架的源 ...
- week_4
Andrew Ng 机器学习笔记---by Orangestar Week4_Neural Networks : Representation 1. Non-linear Hypotheses 当特征 ...
- int类型bit都满了之后继续累加
uint8_t的最大值是255,如果再加1那低8位都是0,最后结果也是0 #include<stdio.h> #define uint8_t unsigned char int main( ...
- 【运维笔录】局域网实现HTTPS访问,只需Nginx + mkcert
1)下载安装mkcert wget -O mkcert https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1 ...
- P5380 [THUPC2019]鸭棋
题面 查看题面 题目背景 鸭棋是一种风靡鸭子界的棋类游戏.事实上,它与中国象棋有一些相似之处,但规则不尽相同.在这里,我们将为你介绍鸭棋的规则. 鸭棋在一个 \(10\times 9\)(\(10\) ...
- 用Java写一个分布式缓存——缓存管理
前言 之前也用过一些缓存中间件,框架,也想着自己是不是也能用Java写一个出来,于是就有了这个想法,打算在写的过程中同步进行总结 源码:weloe/Java-Distributed-Cache (gi ...
- GF_CLR初始用 - 正式版
参照:DeerGF_Wolong框架使用教程 与tackor老哥的踩坑日记所编写,第二次尝试,总结第一次经验重新来. 点击链接加入群聊[Gf_Wolong热更集合] 一. 部署 HybridCLR(W ...
- 读Java8函数式编程笔记08_测试、调试和重构
1. Lambda表达式的单元测试 1.1. 单元测试是测试一段代码的行为是否符合预期的方式 1.2. Lambda表达式没有名字,无法直接在测试代码中调用 1.2.1. 将Lambda表达式放入一个 ...
- Java微服务随机掉线排查思路
背景 我们的业务共使用11台(阿里云)服务器,使用SpringcloudAlibaba构建微服务集群,共计60个微服务,全部注册在同一个Nacos集群 流量转发路径: nginx->spring ...
- 【随笔记】NDK 编译开源库 SQLite3
NDK 编译环境搭建请参考:[工作笔记]NDK 编译开源库 nghttp2/openssl/curl_lovemengx的博客-CSDN博客 一.下载源代码 wget https://github.c ...