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的更多相关文章

  1. Redis 安装,主从配置及Sentinel配置自动Failover

    1.安装redis 首页地址:http://redis.io/ 下载地址:http://download.redis.io/ 下载最新的源码包 tar -zxvf redis-stable.tar.g ...

  2. Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)

    Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...

  3. Redis Sentinel配置小记

    Sentinel是一个管理多个redis实例的工具,它可以实现对redis的监控.通知.自动故障转移.sentinel不断的检测redis实例是否可以正常工作,通过API向其他程序报告redis的状态 ...

  4. Redis哨兵模式(sentinel)部署记录(主从复制、读写分离、主从切换)

    部署环境: CentOS7.5  192.168.94.11 (master) 192.168.94.22 (slave0) 192.168.94.33 (slave1) 192.168.94.44 ...

  5. alibaba/Sentinel 分布式 系统流量防卫兵

    Sentinel: 分布式系统的流量防卫兵 Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多 ...

  6. Redis Sentinel初体验

        自Redis增加Sentinel集群工具以来,本博主就从未尝试过使用该工具.最近在调研目前主流的Redis集群部署方案,所以详细地看了一遍官方对于Sentinel的介绍并在自己的台式机上完成了 ...

  7. Redis主从集群以及Sentinel的配置

    安装完redis后,修改几个redis从节点的配置文件redis.conf,主要是加入主节点位置 slaveof 另外需要修改的地方包括,这样允许其他的从节点连入 bind 0.0.0.0 prote ...

  8. Redis(十五):哨兵Sentinel

    Redis哨兵 Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你 ...

  9. Sentinel限流示例:编码和注解限流

    一.Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度保护服务的稳定性. Sentine ...

  10. redis复制集(sentinel)

    https://www.jianshu.com/p/45ffd2a84143 内核配置 cat >> /etc/rc.local << EOF echo never > ...

随机推荐

  1. context状态树

    provider customer 父组件 创建context对象并导出 export const AddContext = React.createContext<any>({}) 导出 ...

  2. django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: rest_framework_swagger

    在启动服务时报django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: re ...

  3. 【nginx】代理设置Host

    旧文章从语雀迁移过来,原日期为2021-02-18 nginx 的 proxy 模块使我们经常会用到的模块之一,比如我们常用的 nginx 反向代理. 反向代理我们一般有这么几行配置代码: locat ...

  4. Python3套接字(socket)通讯(TCP)

    最近写了一个工程,用作运维的,所以研究了一下Python的TCP通讯(服务器挂一个脚本,电脑挂一个脚本,就可以通过此通讯进行编码加密后传输取回想要的内容) 服务端: from socket impor ...

  5. 火山引擎DataLeap数据调度实例的 DAG 优化方案

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,并进入官方交流群 实例 DAG 介绍 DataLeap 是火山引擎自研的一站式大数据中台解决方案,集数据集成.开发.运维.治理.资产管理能力 ...

  6. [BUUCTF]洞拐洞拐洞洞拐

    [BUUCTF] 洞拐洞拐洞洞拐 问题链接:https://buuoj.cn/challenges#洞拐洞拐洞洞拐 问题附件是一张图片. 一. 图片分析 查看图片,发现是由有规律的黑白像素构成的PNG ...

  7. Educational Codeforces Round 142 (Rated for Div. 2) A-D

    比赛链接 A 题解 知识点:贪心. 代码 #include <bits/stdc++.h> using namespace std; using ll = long long; bool ...

  8. IO多路复用完全解析

    上一篇文章以近乎啰嗦的方式详细描述了BIO与非阻塞IO的各种细节.如果各位还没有读过这篇文章,强烈建议先阅读一下,然后再来看本篇,因为逻辑关系是层层递进的. 1. 多路复用的诞生 非阻塞IO使用一个线 ...

  9. STL序列式容器使用注意、概念总结

    引入 最近看了<STL源码剖析>的第 4 章和第 5 章,介绍了 C++ STL 中的序列式容器和关联式容器,本文将总结序列式容器的基础概念,不会详细它们的实现原理(想知道自个儿看书吧,我 ...

  10. 关于计算机与常用DOS命令

    计算机 计算机 计算机由软件和硬件组成. 能够按照程序运行,自动,高速处理海量数据的现代化智能电子设备. 计算机硬件 CPU 主板 内存 电源.主机箱 硬盘 显卡 键盘.鼠标(输入设备) 显示器(输出 ...