Tag Archives: UnknownHostException: xxx

Unknownhostexception: XXX, an error is reported when using the Nacos remote call service (load balancing)

Remember, this kind of error occurs in the future because @ loadbalanced is not added to the getresttemplate () method in the configuration file of the consumer side to enable the load balancing function, so Nacos reports the error of “no host found”!

The front-end request error page is as follows:

 

Cause analysis:

1. First of all, Nacos has its own load balancing function. Why?Please see the figure below:

 

2. Because Nacos integrates ribbon, you can use resttemplate to remotely call the service for load balancing, and then successfully find the service under the Nacos registration service center. You just don’t know what algorithm to use to select the service provider, so an error is reported – no host exception is found.

 

  Solution:

Add “@ loadbalanced” above the method to get resttemplate in the configuration file to enable the load balancing function.

Done!