package cn.xbz.clientribbonhystrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/test")
    @HystrixCommand(fallbackMethod = "testError")
    public String test(String user) {
        return restTemplate.getForObject("http://service/hello?user=" + user, String.class);
    }


    public String testError(String user){
        return "sorry , " + user + " the ribbon is error ~";
    }
}