我有两个服务“产品服务”和“评级服务”。我正在打一个从产品服务到评级服务的休息电话以获取数据。我已经在产品服务中编写了重试配置,并期望每当评级服务引发异常时,产品服务都会根据配置重试其余调用。但它没有发生。每当从 rating-service 抛出异常时,product-service 也会抛出异常而不重试和回退。请在下面找到这两种服务的代码。在此处检查这两项服务的代码。
产品服务 >> ProductServiceImpl.java
@Retry(name = "rating-service", fallbackMethod = "getDefaultProductRating")
public List<ProductRatingDTO> getProductRating(String id) {
String reqRatingServiceUrl = ratingServiceUrl + "/" + id;
log.info("Making a request to " + reqRatingServiceUrl + " at :" + LocalDateTime.now());
ResponseEntity<List<ProductRatingDTO>> productRatingDTOListRE = restTemplate.exchange(reqRatingServiceUrl,
HttpMethod.GET, null, new ParameterizedTypeReference<List<ProductRatingDTO>>() {
});
List<ProductRatingDTO> productRatingDTOList = productRatingDTOListRE.getBody();
log.info("Retrieved rating for id {} are: {}", id, productRatingDTOList);
return productRatingDTOList;
}
public List<ProductRatingDTO> getDefaultProductRating(String id, Exception ex) {
log.warn("fallback method: " + ex.getMessage());
return new ArrayList<>();
}
产品服务 >> application.yml
resilience4j.retry:
instances:
rating-service:
maxAttempts: 3
waitDuration: 10s
retryExceptions:
- org.springframework.web.client.HttpServerErrorException
ignoreExceptions:
- java.lang.ArrayIndexOutOfBoundsException
评级服务 >> RatingsServiceImpl.java
@Override
public List<RatingsDTO> getRatings(String productId) {
log.info("Ratings required for product id: "+productId);
List<RatingsDTO> ratingsDTOList = ratingsRepository.getRatingsByProductId(productId);
log.info("Ratings fetched for product id {} are : {}",productId,ratingsDTOList);
if (ThreadLocalRandom.current().nextInt(0,5) == 0){ // Erratic block
log.error("Erratic");
throw new org.springframework.web.client.HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
}
return ratingsDTOList;
}
请让我知道我在哪里做错了?