zoukankan      html  css  js  c++  java
  • hystrix 给方法加断路器

    添加依赖

    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>

    1.启动类

    @SpringBootApplication
    @EnableDiscoveryClient
    @ComponentScan("Cloud_Hystrix.*")
    @EnableCircuitBreaker
    public class HystrixController {
    public static void main(String[] args) {
    SpringApplication.run(HystrixController.class, args);
    }
    }

    2,controller

    @RestController
    @RequestMapping(value="/reqmap",produces={"application/json;charaset=utf-8"},method=RequestMethod.GET)
    public class HystrixReqMap {
    @Autowired
    HystrixService hystrixService;
    @RequestMapping("")
    public String reqmap(String param){
    return hystrixService.reqmap(param);
    }
    }

    3.service

    @Service
    public class HystrixService {
    @HystrixCommand(fallbackMethod="fail")
    public String reqmap(String param){
    if(param.equals("aaa")){
    throw new RuntimeException();
    }
    return param+"--hystrix";
    }
    public String fail(String param){
    return "runtimeException";
    }
    }

  • 相关阅读:
    单调栈
    P1164 小A点菜
    P1156 垃圾陷阱
    P1140 相似基因
    P1136 迎接仪式
    P1133 教主的花园
    P1131 [ZJOI2007]时态同步
    P1130 红牌
    利用SQLite在android上实现增删改查
    利用SQLite在android上创建数据库
  • 原文地址:https://www.cnblogs.com/wangjing666/p/7053691.html
Copyright © 2011-2022 走看看