SpringCloud_断路器、服务网关和分布式配置中心

SpringCloud有五大神兽,包括:服务中心(即注册中心)、负载均衡、断路器、服务网关、分布式配置中心
在https://mp.csdn.net/mdeditor/89673212# 此博客内已经描述了注册中心和负载均衡的实现,此处就不在赘述,此文对断路器、服务网关和分布式配置中心的实现进行详细描述。

(一)断路器(Hystrix)

断路器类似于我们生活中的保险丝,在系统中使用断路器通过隔离限流熔断降级等策略,避免一个服务访问出现延迟时,导致所有请求阻塞,造成的系统崩掉。

  1. 服务提供端导入依赖包
    User_service_hystrix_8002的pom.xml
  <!--hystrix断路器支持-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
  1. 服务提供端提供托底函数
    UserController
package cn.itsource.springcloud.controller;

import cn.itsource.springcloud.client.UserClient;
import cn.itsource.springcloud.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/provider")
public class UserController implements UserClient {

    @HystrixCommand(fallbackMethod = "getUserFailBack") //出现短
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值