How to ensure calling of fallback method? How to call my method from another Bean?

35 Views Asked by At

My fallback method handleCitizenDown{} is not executed by any means! I saw a solution I should write my method in another Bean but I don't understand how. My URL and other dependencies work fine just the method is not called when it is failed.

@GetMapping(path = "/id/{id}")
@HystrixCommand(fallbackMethod = "handleCitizenDown")
public ResponseEntity<VaccinationAndCitizenResponse>
        getAllCitizenListByCenterId(@PathVariable Integer id){

    VaccinationAndCitizenResponse citizenResponse = new VaccinationAndCitizenResponse();
    VaccinationCenter center = centerRepo.findById(id).get();
    citizenResponse.setCenter(center);
    List<CitizenModel> citizenModelList =
            restTemplate.getForObject("http://CITIZEN-SERVICE/citizen/id/"+id, List.class);
    citizenResponse.setCitizenModels(citizenModelList);
    return new ResponseEntity<>(citizenResponse, HttpStatus.OK);
}


public ResponseEntity<VaccinationAndCitizenResponse> handleCitizenDown(@PathVariable Integer id){
    VaccinationAndCitizenResponse citizenResponse = new VaccinationAndCitizenResponse();
    VaccinationCenter center = centerRepo.findById(id).get();
    citizenResponse.setCenter(center);
    return new ResponseEntity<>(citizenResponse, HttpStatus.OK); }

enter image description here

0

There are 0 best solutions below