Feign client and eureka service are not on the same server, service access report connection refused error

  Recently, the technical architecture of a project of the company is the springcloud family bucket. Of course, microservice management is eureka. The client call is a feign call. Close to the production release stage. We want to deploy two instances of each eureka service to load balance the server. Just started two After the machine's service is up, the project runs seemingly no problem, but we tested to verify multiple situations. We stopped the service of a server and kept only the feign client. When the external request hit the feign client, an error was reported. Already,

  exception is feign.RetryableException: Connection refused (Connection refused) executing GET http://...

  So I opened the eureka interface to check the service status. The status of the service is normal, but it looks like the feign client does indeed access, and I start the service of the machine where the feign client is located. The other service is stopped and accessed again. , Ok, no error, it's normal, just try it a few times and find that the feign client and service provider are not in the same server will report this error, firstly because the instance name is seen when the multi-service instance environment is just started It is displayed on localhost: XXX, so it was registered with ip from the beginning

eureka.instance.prefer-ip-adderss = true
eureka.instance.instance-id = ${spring.cloud.client.ip-address}:${server.port}

 

 

The above picture shows all ip plus ports. Before there is no ip registration method, there will be an instance of localhost: port. In theory, I think that the Feign client should be able to access the service when it is accessed, but it is not possible. I hover the mouse over the instance name and look at the lower left corner

 

 This picture is the one that can be accessed after the last modification, and it is displayed correctly. The localhost displayed here before the modification shows that the exposed host name is still the actual server, so the eureka service is given a host name when registering The machine IP address is sufficient, add the following configuration based on the previous configuration

eureka.instance.hostname= ${spring.cloud.client.ip-address}

 Restart the service and re-register to eureka to successfully verify

Guess you like

Origin www.cnblogs.com/kevin-w/p/12674483.html