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. Ubuntu:Docker 容器操作

    创建容器 1.docker run [option] 镜像名 [向启动容器中传入的命令] 常用可选说明 -i 表示以"交互模式"运行容器 -t 表示容器启动后会进入其命令行.加入这 ...

  2. 带cookie爬取内容demo

    概述: 在爬取一些网站时,需要在headers中加入cookie才能返回数据,原因是存在反爬机制,我们需要尽可能的伪装成浏览器在访问这个url 时发送的数据包. demo演示:

  3. WCF 服务容器化的一些问题

    背景 目前项目当中存有 .NET Framework 和 .NET Core 两种类型的项目,但是都需要进行容器化将其分别部署在 Windows 集群和 Linux 集群当中.在 WCF 进行容器化的 ...

  4. 【带你读论文】向量表征经典之DeepWalk

    摘要:详细讲解DeepWalk,通过随机游走的方式对网络化数据做一个表示学习,它是图神经网络的开山之作,借鉴了Word2vec的思想. 本文分享自华为云社区<[论文阅读] (25) 向量表征经典 ...

  5. Linux 驱动像单片机一样读取一帧dmx512串口数据

    硬件全志R528 目标:实现Linux 读取一帧dmx512串口数据. 问题分析:因为串口数据量太大,帧与帧之间的间隔太小.通过Linux自带的读取函数方法无法获取到 帧头和帧尾,读取到的数据都是缓存 ...

  6. Redis 正则扫描key并删除

    扫描key /** * @param key * @return * @Description: 通过Scan的方式迭代key */ public Set<String> scanKeys ...

  7. 通过this引用成员方法-类的构造器

    通过this引用成员方法 this代表当前对象,如果需要引用的方法就是当前类中的成员方法,那么可以使用"this成员方法"的格式来使用方法引用.首先是简单的函数式接口︰ 下面是一个 ...

  8. spring.jackson.default-property-inclusion 不生效问题分析

    背景 项目里每个返回体里都有@JsonInclude(JsonInclude.Include.NON_NULL) 这个注解,也就是不返回null字段 想有没有办法全局配置一下,这样就不用每个类都加这个 ...

  9. KStudio-Java程序连接KingbaseES数据库异常

    错误信息: --KStudio客户端工具错误信息 The conncetion attempt failed.Reason:connect time out --Java应用程序控制台日志 Cause ...

  10. springcloud12-spring cloud stream

    1.基础说明 官网:https://spring.io/projects/spring-cloud-stream#overview   文档:https://docs.spring.io/spring ...