I have 2 microservice, both are registered with eureka and runn individually from my local. But the problem happens when i am trying to access one microservice with another microservice using FeignClient.

Here are 2 microservice: SecondMicroservice- the source

Application.yml:

eureka: password: password client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${vcap.services.${PREFIX:}eurekaURL.credentials.uri:http://user:password@XXXXXXXXX}/eureka/ instance: healthCheckUrlPath: /health leaseRenewalIntervalInSeconds: 10 hostname: ${vcap.application.uris[0]:localhost} #hostname: ${vcap.application.uris[0]:${eureka.instance.metadataMap.instanceId}} nonSecurePort: 80 metadataMap: instanceId: "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}" # password: "${security.user.password:password}" statusPageUrlPath: /info

Bootstrap.yml:

server: port: 8080 spring: application: name: SecondMicroService config: name: ${spring.application.name} profiles: active: dev cloud: config: uri: ${vcap.services.configserver.credentials.url:http://user:password@localhost:8888} enabled: true

Controller: @RestController @RequestMapping public class SecondMicroServiceController {

@RequestMapping(value="app/testUrl",method=RequestMethod.GET)
public  String processGetAppTestUrl(@RequestBody(required=false) Object requestBean){   
//API Call
return "hello world!!"; 
}

}

ThirdMicroService- the one which is trying to access the SECONDMICROSERVICE

Application.yml:

eureka: password: password client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${vcap.services.${PREFIX:}eurekaURL.credentials.uri:http://user:password@XXXXXXXXXXXXX}/eureka/ instance: healthCheckUrlPath: /health leaseRenewalIntervalInSeconds: 10 hostname: ${vcap.application.uris[0]:localhost} #hostname: ${vcap.application.uris[0]:${eureka.instance.metadataMap.instanceId}} nonSecurePort: 80 metadataMap: instanceId: "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}" # password: "${security.user.password:password}" statusPageUrlPath: /info

Bootstrap.yml:

server: port: 9005 spring: application: name: ThirdMicroServiceClient config: name: ${spring.application.name} profiles: active: dev cloud: config: uri: ${vcap.services.configserver.credentials.url:http://user:password@localhost:8888} enabled: false

Controller:

@RestController public class ThirdMicroServiceController {

@Autowired      
SecondServiceAccessingClient  secondServiceAccessingClient;

@RequestMapping(value="app/testUrl")
public  String getresponse(){   
//API Call
return (String)secondServiceAccessingClient.getresponse();

    //return"Hello Thirdapp";
}

}

Client:

@FeignClient("SECONDMICROSERVICE") public interface SecondServiceAccessingClient {

 @RequestMapping("app/testUrl")
    String getresponse();

}

Application Class:

@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class ThirdMicroServiceClientApplication {

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

}

Comment From: spencergibb

Source code pasted in an issue is very difficult to work with. Please supply a github project or a zip file with a minimal project.

Comment From: sharmarohit707

I have created 2 gist for the 2 projects. Please download and you can check

https://gist.github.com/sharmarohit707/5f8b7da0e942b6266654f999db2c74f2

https://gist.github.com/sharmarohit707/090fbf4096a62c1c28584f58742d3430

Comment From: ryanjbaxter

Rather than using a Gist can you provide the complete source code in a GitHub repo or attach it as a zip file?

Comment From: sharmarohit707

If i could i would have. My code is tied with my company specific things which i cant share. Hence has put as much info as i could. Moreover you can download the gist and run like a normal project. Thanks for the reply.

Comment From: ryanjbaxter

I am not trying to be a pain, but you were able to extract the code into Gists so I don't understand why you couldn't just extract it into a working Maven project. It just makes it easier for us to reproduce the problem. Also if you could provide the complete stacktrace for the problem that would be helpful.

Comment From: shenqianfan

I know how this happen, I have solve this problem

Comment From: zios07

@shenqianfan can you, please, show us how you solved it ?

Comment From: asrar84

I faced the same Issue. It is because of port mismatch in my case.

In my case:- I am accessing ServiceB from ServiceA. ServiceB is deplyoed on JBoss port 8080, with doker port mapping 6700:8080

Scenario in which I faced issue:- server: context-path: /ema-user-service port: 6700

Solution:- server: context-path: /ema-user-service port: 8080

Comment From: Laxminarsaiah

The problem is, you put server port details in bootstrap.yml which not correct place you should keep those details in application.yml file only.

If you put server details in bootstrap.yml then while starting of the application server will look into application.yml/.properties file only. so if it available in application.yml/.properties file then it will take otherwise it will take default port number that may already in use.

Comment From: spencergibb

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

Comment From: 401825317

@shenqianfan 我现在也遇到了这个问题,能告诉我解决方案吗

Comment From: ruanjianershu

I have 2 microservice, both are registered with eureka and runn individually from my local. But the problem happens when i am trying to access one microservice with another microservice using FeignClient.

Here are 2 microservice: SecondMicroservice- the source

Application.yml:

eureka: password: password client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${vcap.services.${PREFIX:}eurekaURL.credentials.uri:http://user:password@XXXXXXXXX}/eureka/ instance: healthCheckUrlPath: /health leaseRenewalIntervalInSeconds: 10 hostname: ${vcap.application.uris[0]:localhost}

hostname: ${vcap.application.uris[0]:${eureka.instance.metadataMap.instanceId}}

nonSecurePort: 80 metadataMap: instanceId: "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}"

password: "${security.user.password:password}"

statusPageUrlPath: /info

Bootstrap.yml:

server: port: 8080 spring: application: name: SecondMicroService config: name: ${spring.application.name} profiles: active: dev cloud: config: uri: ${vcap.services.configserver.credentials.url:http://user:password@localhost:8888} enabled: true

Controller: @RestController @RequestMapping public class SecondMicroServiceController {

@RequestMapping(value="app/testUrl",method=RequestMethod.GET) public String processGetAppTestUrl(@RequestBody(required=false) Object requestBean){ //API Call return "hello world!!"; } }

ThirdMicroService- the one which is trying to access the SECONDMICROSERVICE

Application.yml:

eureka: password: password client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${vcap.services.${PREFIX:}eurekaURL.credentials.uri:http://user:password@XXXXXXXXXXXXX}/eureka/ instance: healthCheckUrlPath: /health leaseRenewalIntervalInSeconds: 10 hostname: ${vcap.application.uris[0]:localhost}

hostname: ${vcap.application.uris[0]:${eureka.instance.metadataMap.instanceId}}

nonSecurePort: 80 metadataMap: instanceId: "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}"

password: "${security.user.password:password}"

statusPageUrlPath: /info

Bootstrap.yml:

server: port: 9005 spring: application: name: ThirdMicroServiceClient config: name: ${spring.application.name} profiles: active: dev cloud: config: uri: ${vcap.services.configserver.credentials.url:http://user:password@localhost:8888} enabled: false

Controller:

@RestController public class ThirdMicroServiceController {

``` @Autowired
SecondServiceAccessingClient secondServiceAccessingClient;

@RequestMapping(value="app/testUrl") public String getresponse(){ //API Call return (String)secondServiceAccessingClient.getresponse();

//return"Hello Thirdapp"; } ``` }

Client:

@FeignClient("SECONDMICROSERVICE") public interface SecondServiceAccessingClient {

@RequestMapping("app/testUrl") String getresponse(); }

Application Class:

@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class ThirdMicroServiceClientApplication {

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

可以共享下解决方案吗

Comment From: SparkZhou1994

I know how this happen, I have solve this problem

How To solve this problem

Comment From: SparkZhou1994

The problem is, you put server port details in bootstrap.yml which not correct place you should keep those details in application.yml file only.

If you put server details in bootstrap.yml then while starting of the application server will look into application.yml/.properties file only. so if it available in application.yml/.properties file then it will take otherwise it will take default port number that may already in use.

It doesn't work

Comment From: sanwancoder

Check your ip and port .

Perhaps, your url is wrong.

Comment From: puddingzsq

我也发生了这样的异常,请问是怎么解决的?

Comment From: pandalin

I know how this happen, I have solve this problem

你知道个锤子

Comment From: redford42

I solved this problem turns out there are two same remote services and one of them didn‘t start success so i turn down the duplicate service hope this solve you problem


解决了 打开注册中心发现被调用的服务有两 然后其中一个估计是启动没成功还是啥的,反正就是有问题,估计分发到有问题的服务了 希望解决你的问题

Comment From: gengxiz

I solved this problem

turns out there are two same remote services and one of them didn‘t start success so i turn down the duplicate service hope this solve you problem 解决了 打开注册中心发现被调用的服务有两 然后其中一个估计是启动没成功还是啥的,反正就是有问题,估计分发到有问题的服务了 希望解决你的问题

我觉得你说得对,发生这个问题,正是服务刚被重启的时候

Comment From: redford42

You can open eureka,and click the service you remote use Either it's url is wrong or it's not start up right This time i got this problem because we locked the prefix of url,so my local start up service can‘t be access by other service.

你可以点开eureka,点一下你远程调用的服务 要么是服务启动的时候出了问题,要么是服务的url有问题 (我这次又报错是因为服务的url前缀被写死了,所以我本地启动服务是远程调用不到的

Comment From: szfiligon

this problem happens when an related service stop or restart, when a server being stoped, all the processing request can't get return from the service, and later request will have error about "Load balancer does not have avaiable server for client...". so if you find "Connection refused..." and "Load balance ..." exist together, the server being stoped is a most prossible sisutation.

following is my test result for this bug: Spring Cloud Netflix feign.RetryableException: Connection refused: connect executing GET http://SECONDMICROSERVICE/app/testUrl

Comment From: bacinggithub

change ip localhost to ip IPv4 address