Construire le microservice Springcloud (quatre) fusibles Hystrix

Le contrôleur du microservice de compte springcloud ajoute l'annotation HystrixCommand

MyController  

@RestController
public class MyController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/a2b")
    @HystrixCommand(fallbackMethod = "hystrixFallback", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000"),
            @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1000"),})
    public String memTest() {
        String str = restTemplate.getForObject("http://bill-server/billTest", String.class);
        return str;
    }
    public String hystrixFallback() {
        return "this is hystrixFallback";
    }
}

Résultat final: appelez la méthode par défaut à renvoyer après l'échec de l'appel.

Le fusible Hystrix est terminé!

Je suppose que tu aimes

Origine blog.csdn.net/x18094/article/details/114801524
conseillé
Classement