gpt4 book ai didi

java - 嵌套异常是 org.springframework.web.client.ResourceAccessException : I/O error on GET request for "*": Connection refused (Connection refused);

转载 作者:行者123 更新时间:2023-11-30 06:06:36 35 4
gpt4 key购买 nike

我试图从我的应用程序访问 Rest API。当该 API 不在线时,我的应用程序发生了上述错误。我正在使用 Spring Boot 。我想知道,有什么方法可以在访问该网址之前检查该网址的可用性。

 String URL = "http://172.17.42.1:4001/v2/keys" + key + "/running";
instance = restTemplate.getForObject(URL, Instance.class);

最佳答案

要了解服务的可用性,您必须点击 URL,没有其他方法。

但是,spring-cloud-netflix-hystrix是为了处理此类问题而构建的。

Circuit Breaker文档

Netflix’s Hystrix library provides an implementation of the Circuit Breaker pattern: when we apply a circuit breaker to a method, Hystrix watches for failing calls to that method, and if failures build up to a threshold, Hystrix opens the circuit so that subsequent calls automatically fail. While the circuit is open, Hystrix redirects calls to the method, and they’re passed on to our specified fallback method

有很多 Material 可供学习。

关于java - 嵌套异常是 org.springframework.web.client.ResourceAccessException : I/O error on GET request for "*": Connection refused (Connection refused);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51183089/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com