Hi All,
I am using Spring boot for development . Currently i am
testing hystrix fallback mechanism . Issue is when ever i tried to make a rest call control is immediately falling back to fallback method.Below is my code .If i removed Hystrix command it is working fine.
Kindly help on this
package com.ibm.oilngas.controllers;
import java.util.ArrayList;
import java.util.List;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
@Service
public class FallBackService {
private final RestTemplate restTemplate;
public FallBackService(RestTemplate rest) {
this.restTemplate = rest;
}
@HystrixCommand(fallbackMethod = "plantactivityfallback")
public List<PlantactivityBean> readingList() {
ResponseEntity<List<PlantactivityBean>> rateResponse = restTemplate.exchange(
"http://localhost:9001/getallplantactivity", HttpMethod.GET, null,
new ParameterizedTypeReference<List<PlantactivityBean>>() {
});
List<PlantactivityBean> rates = rateResponse.getBody();
return rates;
}
public List<PlantactivityBean> plantactivityfallback() {
ArrayList aa = new ArrayList();
aa.add("Service is Not avilable Currently !! Please try again!!!");
return aa;
}
}