Dubbo整合Hystrix断路器(五)
Hystrix信号量限流策略
package com.bfxy.order.web;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class OrderController {
@HystrixCommand(
commandKey = "/createOrder",
commandProperties = {
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"),
@HystrixProperty(name = "execution.isolation.semaphore.maxConcurrentRequests", value = "3")
},
fallbackMethod = "createOrderFallbackMethod4Semaphore"
)
@RequestMapping("/createOrder")
public String createOrder(@RequestParam("cityId") String cityId,
@RequestParam("platformId") String platformId,
@RequestParam("userId") String userId,
@RequestParam("suppliedId") String suppliedId,
@RequestParam("goodsId") String goodsId) throws InterruptedException {
return "下单成功";
}
public String createOrderFallbackMethod4Semaphore(@RequestParam("cityId") String cityId,
@RequestParam("platformId") String platformId,
@RequestParam("userId") String userId,
@RequestParam("suppliedId") String suppliedId,
@RequestParam("goodsId") String goodsId){
System.err.println("------信号量限流降级策略执行------");
return "hystrix semaphore !";
}
}