0

Using Feign to access services that I register on Eureka is a breeze. I am trying to use Feign to access external services and struggling with the basics.

I am playing with a service on Bluemix however to simplify the problem at hand, I am using a simple service.

My Proxy appears as follows:

//@FeignClient(name = "country-service-client", url = "https://country.io")
@FeignClient(name = "another-country-service-client", url = "http://restcountries.eu/rest/v2/name/Australia")

public interface SimpleServiceProxy {

    //This one works
    @RequestMapping(method = RequestMethod.GET, value = "/names.json", produces = "application/json")
    String getCountries();

    //This one does not work... This is used in conjunction where the url in the Fiegn Client annotation reads as - http://restcountries.eu/rest/v2
    @RequestMapping(method = RequestMethod.GET, value = "/name/{country}", produces = "application/json")
    public String getCountryInfo(@PathVariable("country") String country);



     //This one doesn't work either
    //@RequestMapping(method = RequestMethod.GET, value = "/name/Australia", produces = "application/json")
    public String getCountryInfoHardcodedWithinMethod();
}

    //This works however I would want to pass parameters and path variables to the URL
    @RequestMapping(method = RequestMethod.GET, produces = "application/json")
    public String getCountryInfoHardcodedAtFeignClientAnnotation();
}

I have tried a few variants (see the code above) and the last one where the URL is hardcoded at the Feign Client annotation works. The others throw a TimeoutException.

java.util.concurrent.TimeoutException: null
    at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:958) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand.access$400(AbstractCommand.java:59) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand$11.call(AbstractCommand.java:573) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand$11.call(AbstractCommand.java:565) ~[hystrix-core-1.5.3.jar:1.5.3]
    at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:139) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) ~[rxjava-1.1.5.jar:1.1.5]
    at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1099) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:1116) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99) ~[hystrix-core-1.5.3.jar:1.5.3]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_112]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_112]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_112]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_112]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_112]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_112]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_112]

I am puzzled and trying to figure things out. I want to get the hardcoded methods working before trying to figure out why the PathVariables aren't working.

What am I missing? (or doing incorrectly here)?

Manglu
  • 10,744
  • 12
  • 44
  • 57

1 Answers1

1

I just tried this simple application and it worked fine for me using Dalston.RC1

@SpringBootApplication
@EnableFeignClients
@RestController
public class DemoApplication {

    @Autowired
    SimpleServiceProxy proxy;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/")
    public String getCountry() {
        return proxy.getCountryInfo("Australia");
    }
}

@FeignClient(name = "another-country-service-client", url ="http://restcountries.eu/rest/v2")
interface SimpleServiceProxy {
    @RequestMapping(method = RequestMethod.GET, value = "/name/{country}", produces = "application/json")
    public String getCountryInfo(@PathVariable("country") String country);
}

The exception in your question is indicating a timeout via Hystrix when making the request. You can try disabling Hystrix and seeing if it goes away using feign.hystrix.enabled=false.

Ryan Baxter
  • 1,237
  • 2
  • 8
  • 16
  • Ryan, Thanks. I was using Brixton.SR6 with 1.4.5 release of spring boot. I believe feign.hystrix.enabled is not available (STS does not show this on code-assist). – Manglu Mar 27 '17 at 22:44
  • Using 1.4.5 (or 1.5.1 or 1.5.2) with Dalston.RC1 throws up a number of maven errors - An example error is : For artifact {org.springframework.cloud:spring-cloud-starter-feign:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources) – Manglu Mar 27 '17 at 22:47
  • Just because STS doesnt have this listen in its autocomplete doesnt mean it is not valid. See the Brixton documentation http://cloud.spring.io/spring-cloud-static/Brixton.SR7/#spring-cloud-feign-hystrix. I would suggest you at least consider upgrading to `Brixton.SR7` if not the latest Camden release. As far as those Dalston errors go, please open another issue/question on SO. – Ryan Baxter Mar 27 '17 at 23:37
  • 1
    You should add spring's milestone repo when using Dalston.RC1. – Kane Mar 27 '17 at 23:39
  • Ryan, Thanks. It has started working now (still using Brixton.SR6 and 1.4.5). I don't know why it was not working yesterday and with absolutely no change it is working today. It certainly was and is puzzling. It certainly was not a network issue as I could access the URLs via a browser yesterday. – Manglu Mar 28 '17 at 00:08
  • @Kane, Thanks. I was under the incorrect impression that even RCs were available in the maven repo. I will add the milestone repo to my pom and check that out. – Manglu Mar 28 '17 at 23:08
  • @RyanBaxter am getting feign.RetryableException: restcountries.eu executing GET http://restcountries.eu/rest/v2/name/Australia. Caused by: java.net.UnknownHostException: restcountries.eu – Lijo Oct 23 '20 at 10:37