Hello, Can someone explain how FeignClient knows which service registered with Eureka is the right one for it? I saw a couple of issues which I thought might be caused by client not being able to locate the corresponding service provider (TimeoutException: null, or message about load balancer not finding service).
While FeignClient works with URLs: @FeignClient(name = "abc", url = "http://localhost:8094") public interface MyClient { @RequestMapping(method = RequestMethod.GET, value = "/data/ids") List getDataByIds(@RequestParam("ids") String[] ids); } I was not yet able to tell it to connect to service by Eureka service name lookup.
I guess my question is "if service is registered with Eureka under my-service name/id, how do you tell FeignClient to look it up by that name (my-service)"? Thanks!
Marcin
Comment From: spencergibb
"my-servive" should be the name of the feign client, not abc.
Comment From: macheeto
Hi Spencer, This is from Cloud Netflix documentation (http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html): "In the @FeignClient annotation the String value ("stores" above) is an arbitrary client name, which is used to create a Ribbon load balancer ..."
How can an arbitrary name (random?) be used to look up a particular service (my-service)? Also could you actually explain how Feign talks to Eureka? All the docs I could find show "name" property being used to look up config in yaml/properties file (from http://stackoverflow.com/questions/29278005/can-i-configure-a-feignclient-url-using-a-properties-yml-file): @FeignClient("foo") interface Client { ... } foo.ribbon.listOfServers: localhost:9000
That's not the same as looking up service in Eureka by "foo". Thanks,
Marcin
Comment From: spencergibb
That comment is about using ribbon without eureka. With eureka it needs to be the service ID.
Comment From: macheeto
Hi Spencer, When I switch from url to name/value property I'm getting the null timeout issue: https://github.com/spring-cloud/spring-cloud-netflix/issues/768
I verified that my POM dependencies were like the ones in your example: https://github.com/spring-cloud-samples/feign-eureka/blob/master/client/pom.xml
I added a comment in issue 768. Thanks for all your help!
Comment From: spencergibb
@macheeto how about a project that reproduces your problem?
Comment From: macheeto
In case someone else runs into this problem: 1) When calling APIs through Ribbon-enabled clients make sure to prefix service id with "http://" protocol, i.e. "http://my-service-id". Passing only service id does not work. 2) I found it easier to use Rest template instead of Feign client. Rest template is easy to configure, especially later when adding OAuth2, load balancing, etc.
private PayloadType callApi(String serviceId, HttpMethod method, String path, Map<String, String> requestParams) {
String uri = "http://" + serviceId;
PayloadType output = null;
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uri).path(path);
for (Map.Entry<String, String> entry : requestParams.entrySet()) {
builder.queryParam(entry.getKey(), entry.getValue());
}
URI apiCall = builder.build().toUri();
log.debug(String.format("%s is calling endpoint: %s", name, apiCall.toString()));
ResponseEntity<PayloadType> response = restTemplate.exchange(apiCall, method, null, new ParameterizedTypeReference<PayloadType>() {});
if (response != null) {
output = response.getBody();
}
return output;
}
3) If you get NullPointer exception as timeout reason just wait for a while. That has something to do with services not seeing each other and goes away after some time.
Comment From: spencergibb
@macheeto spring-cloud-netflix automatically adds "http" for feign. This isn't a problem other people are seeing. Like I said before:
how about a project that reproduces your problem?
Which you didn't do, so we can't reproduce the problems you say you are seeing.
Comment From: momentum123
hi @ryanjbaxter @spencergibb @macheeto getting kind of same issue with feign client getting this error:
Exception in thread "main" feign.RetryableException: ems executing POST http://ems/api/v1.0/sdk/User
at feign.FeignException.errorExecuting(FeignException.java:67)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy124.createNewUser(Unknown Source)
at com.phoenix.sdk.ems.test.UserServiceTests.createUser(UserServiceTests.java:43)
at com.phoenix.sdk.ems.EmsSdkMain.main(EmsSdkMain.java:26)
Caused by: java.net.UnknownHostException: ems
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at feign.Client$Default.convertAndSend(Client.java:133)
at feign.Client$Default.execute(Client.java:73)
at org.springframework.cloud.netflix.feign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:80)
at org.springframework.cloud.netflix.feign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:48)
at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:109)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287)
at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:231)
at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:228)
at rx.Observable.unsafeSubscribe(Observable.java:10151)
at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.drain(OnSubscribeConcatMap.java:286)
at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.onNext(OnSubscribeConcatMap.java:144)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:185)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180)
at rx.Observable.unsafeSubscribe(Observable.java:10151)
at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94)
at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42)
at rx.Observable.unsafeSubscribe(Observable.java:10151)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber$1.call(OperatorRetryWithPredicate.java:127)
at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(TrampolineScheduler.java:73)
at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(TrampolineScheduler.java:52)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:79)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:45)
at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10247)
at rx.Observable.subscribe(Observable.java:10214)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:444)
at rx.observables.BlockingObservable.single(BlockingObservable.java:341)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:117)
at org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:63)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)
... 5 more
this is my client interface
@FeignClient(value = "ems")
public interface UserService extends UserRestService {
}
using eureka for discovery
Comment From: momentum123
service ems is getting registered in eureka and as far as i know feignclient is not able to resolve the host from eureka hence not replacing "ems" with "host:port"
Comment From: momentum123
hi @spencergibb @ryanjbaxter i have found the issue actually my service is running in docker so in eureka hostname is resolved to docker container id and for outside application (not running on docker) that will not be resolved hence getting unknown host exception with container-id as unknownhost so now im putting
eureka.instance.hostname =localhost
but now im getting feign read timeout exception can u help me with that
Comment From: momentum123
hi @spencergibb now have moved my client application to docker the using the same jar which was working absolutely fine now throwing null pointer due to service bean annotated with @feignclient not getting created tried so many random things for fetching bean but still getting null does anyone has any idea y bean creation is failing in docker
Comment From: ryanjbaxter
Please do not comment on the multiple issues with the same problem
Comment From: pkumar53
I tried creating a normal demoeureka server and demo1 and demo2 as my two spring boot microservices and i want them to talk with each other using openFeign. The same thing was working earlier but now I get "There was an unexpected error (type=Internal Server Error, status=500). connect timed out executing GET http://hom2/hr/data". This happens whenever i try feign client with service id hom2 but works fine with url hard coded. Not sure why this is happening. What I detect that Feign client is finding the services in eureka with service id. Please find logs below
2020-02-27 04:36:09.349 INFO 17980 --- [nio-8088-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: hom2.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647 2020-02-27 04:36:09.418 INFO 17980 --- [nio-8088-exec-1] c.n.u.concurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-hom2 2020-02-27 04:36:09.419 INFO 17980 --- [nio-8088-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: hom2 instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=hom2,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null 2020-02-27 04:36:09.433 INFO 17980 --- [nio-8088-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater 2020-02-27 04:36:09.476 INFO 17980 --- [nio-8088-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: hom2.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647 2020-02-27 04:36:09.480 INFO 17980 --- [nio-8088-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client hom2 initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=hom2,current list of Servers=[host.docker.internal:8089],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;] },Server stats: [[Server:host.docker.internal:8089; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 05:30:00 IST 1970; First connection made: Thu Jan 01 05:30:00 IST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0] ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@44fb2d60 2020-02-27 04:36:10.443 INFO 17980 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: hom2.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647 2020-02-27 04:36:11.651 ERROR 17980 --- [nio-8088-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: connect timed out executing GET http://hom2/hr/data] with root cause
java.net.SocketTimeoutException: connect timed out at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_131] at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_131] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_131] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_131] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_131] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_131] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_131] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_131] at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[na:1.8.0_131] at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) ~[na:1.8.0_131]
Comment From: patpro123
Hi all
I see this old thread has some latest entries as well..
I am facing a similar issue.. simple demo project downloaded from here https://github.com/spring-cloud-samples/feign-eureka won't work - since the service name is not resolved. I've made no changes in the code. However it does work for others, which is even more strange. Is there a relation to which IDE I am using? I've tried both IntelliJ and Eclipse, but same error..
Error is this.. 2020-05-21 11:22:32.806 ERROR 16184 --- [nio-7211-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: connect timed out executing GET http://HelloServer/] with root cause
java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_211]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_211]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_211]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_211]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_211]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_211]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_211]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_211]
at sun.net.NetworkClient.doConnect(Unknown Source) ~[na:1.8.0_211]
at sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:1.8.0_211]
at sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:1.8.0_211]
at sun.net.www.http.HttpClient.
Comment From: mithunmohan912
Hi All,
I also faced the same issue at while working with local host . I was able to to figure issue. I have tried to summarized this. kindly have a look. Hope it helps https://stackoverflow.com/questions/59999740/feignclient-not-resolving-eureka-service-name/66188856#66188856