0

私はユーレカに登録するサービスにアクセスするためにファインを使用するのは簡単です。私はFeignを使って外部サービスにアクセスし、基本に苦しんでいます。SpringCloudを外部サービスと連携させるために奮闘する

私はBluemixのサービスで遊んでいますが、手元の問題を簡素化するために、私は簡単なサービスを使用しています。私はいくつかの亜種(上記のコードを参照)、URLを装うクライアント注釈作品でハードコードされた最後のものを試してみました

//@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(); 
} 

次のように

私のプロキシが表示されます。他は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] 

私は困惑して物事を理解しようとしています。 PathVariablesが動作しない理由を理解しようとする前に、ハードコードされたメソッドを動作させたい。

私には何が欠けていますか? (またはここで間違っている)?

答えて

1

私はちょうどこの簡単なアプリケーションを試してみましたが、それが要求を行うとき、あなたの質問に例外がHystrix経由でタイムアウトを表示している 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); 
} 

を使用して私のためにうまく働きました。あなたはHystrixを無効にして、feign.hystrix.enabled=falseを使って遠ざかるかどうか試してみることができます。

+0

Ryan、ありがとう。私はBrixton.SR6を使用していました。私はfeign.hystrix.enabledが利用できないと信じています(STSはコードアシストでこれを表示しません)。 – Manglu

+0

Dalston.RC1で1.4.5(または1.5.1または1.5.2)を使用すると、いくつかのmavenエラーがスローされます。例のエラーは:artifact {org.springframework.cloud:spring-cloud-starter-feign:null :jar}:バージョンを空にすることはできません。 (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources) – Manglu

+0

STSはオートコンプリートでこのリッスンを持っていないからといって、 Brixtonのドキュメントhttp://cloud.spring.io/spring-cloud-static/Brixton.SR7/#spring-cloud-feign-hystrixを参照してください。 最新のCamdenリリースでない場合は、少なくとも「Brixton.SR7」にアップグレードすることをお勧めします。これらのDalstonのエラーが表示される限り、SOに関する別の問題/質問を開いてください。 –

関連する問題