Support circuitbreaker in RestTemplate

pull/300/head
weihu 3 years ago
parent d200d1a710
commit 4da5fed628

@ -39,8 +39,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
*
* @author Haotian Zhang
*/
@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled", havingValue = "true",
matchIfMissing = true)
@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled", havingValue = "true", matchIfMissing = true)
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)

@ -49,7 +49,6 @@ public class PolarisRestTemplateModifier implements ApplicationContextAware, Sma
if (!ObjectUtils.isEmpty(beans)) {
beans.forEach(this::initRestTemplate);
}
}
private void initRestTemplate(String beanName, Object bean) {
@ -57,12 +56,10 @@ public class PolarisRestTemplateModifier implements ApplicationContextAware, Sma
RestTemplate restTemplate = (RestTemplate) bean;
restTemplate.setErrorHandler(polarisRestTemplateResponseErrorHandler);
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}

@ -72,14 +72,14 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
}
}
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) {
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ServiceCallResult resultRequest = null;
try {
resultRequest = builderServiceCallResult(url, response);
}
catch (IOException e) {
LOG.error("Will report response of {} url {}", response, url, e);
throw new RuntimeException(e);
throw e;
}
finally {
consumerAPI.updateServiceCallResult(resultRequest);

@ -50,7 +50,7 @@ public class ServiceAController {
@GetMapping("/getBServiceInfoByRestTemplate")
public String getBServiceInfoByRestTemplate() {
return restTemplate.getForObject("http://polaris-circuitbreaker-example-b//example/service/b/info", String.class);
return restTemplate.getForObject("http://polaris-circuitbreaker-example-b/example/service/b/info", String.class);
}
/**

Loading…
Cancel
Save