Utiliser Feign pour accéder aux services que je m'inscris sur Eureka est un jeu d'enfant. J'essaie d'utiliser Feign pour accéder à des services externes et lutter avec les bases. Je joue avec un service sur Bluemix cependant pour simplifier le problème à portée de main, j'utilise un service simple.Lutter pour que SpringCloud Feign fonctionne avec des services externes
Mon Proxy se présente comme suit:
//@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();
}
J'ai essayé quelques variantes (voir le code ci-dessus) et le dernier où l'URL est codé en dur à l'usine d'annotation client Feindre. Les autres lancent une exception 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]
Je suis perplexe et essayer de comprendre les choses. Je veux que les méthodes codées en dur fonctionnent avant d'essayer de comprendre pourquoi les PathVariables ne fonctionnent pas.
Qu'est-ce qui me manque? (ou faire incorrectement ici)?
Ryan, merci. J'utilisais Brixton.SR6 avec la version 1.4.5 de démarrage au printemps. Je crois que feign.hystrix.enabled n'est pas disponible (STS ne le montre pas sur le code-assist). – Manglu
L'utilisation de 1.4.5 (ou 1.5.1 ou 1.5.2) avec Dalston.RC1 génère un certain nombre d'erreurs maven - Un exemple d'erreur est: Pour artefact {org.springframework.cloud:spring-cloud-starter-feign:null : jar}: La version ne peut pas être vide. (org.apache.maven.plugins: maven-resources-plugin: 2.6: ressources: ressources par défaut: ressources-processus) – Manglu
Tout simplement parce que STS n'a pas cette écoute dans sa saisie semi-automatique ne signifie pas qu'il n'est pas valide. Voir la documentation de Brixton http://cloud.spring.io/spring-cloud-static/Brixton.SR7/#spring-cloud-feign-hystrix. Je vous suggère au moins de mettre à jour vers 'Brixton.SR7' si ce n'est la dernière version de Camden. En ce qui concerne ces erreurs Dalston, veuillez ouvrir un autre numéro/question sur le SO. –