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";
    }
    }

  • 相关阅读:
    Thread.sleep(0)的意义& 多线程详解
    .NET AOP的实现
    UML详解
    asp.net事件委托易理解实例
    2个或多个datable类似于sql inner join 合并查询
    web.cofing(新手必看)
    JS操作URL
    .net对象转Datable
    NPOI读写Excel
    RSA加密
  • 原文地址:https://www.cnblogs.com/wangjing666/p/7053691.html
Copyright © 2011-2022 走看看