1,远程调用基本介绍
1.1,@FeignClient标签的常用属性如下:
name:指定FeignClient的名称,如果项目使用了Ribbon,name属性会作为微服务的名称,用于服务发现
url: url一般用于调试,可以手动指定@FeignClient调用的地址
path: 定义当前FeignClient的统一前缀,当我们项目中配置了server.context-path,server.servlet-path时使用
1.2,两个微服务模块之间,调用者和被调用者
1.2.1,前提:两个服务都已经注册到同一个注册中心;
1.2.2,网络结构
场景1:两个服务部署在同一台服务器,或者同一个网段;
场景2:两个服务在不同的服务器【容易出问题的模式】
1.2.3,被调用者的注册地址,是可以被调用者的运行环境直接访问的;
调用者代码
@FeignClient(name="FEEINTE",path="/feeinte") public interface FeeInterfaceService { @RequestMapping(value="selectAllCi") List<Ci> selectAllCi();
被调用者配置文件
feeinte服务的配置文件
server.port=1903
spring.application.name=FEEINTE
#server端的hostname
eureka.instance.hostname=223.70.130.11
#注册到server的实例id,具备唯一性
eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}/${spring.application.name}
#注册服务时是否使用IP注册,默认false
eureka.instance.prefer-ip-address=true
#server端的ip地址
eureka.instance.ip-address=223.70.130.11
1.2.4,后台运行过程:调用者请求FEEINTE,到eureka注册中心根据FEEINTE获得223.70.130.11和1903,拼接成最终访问地址223.70.130.11:1903/feeinte/selectAllCi
其中feeinte和tomcat/webapps文件夹名称一致;
2,常见异常信息和处理方案
2.1,找不到FEEINTE;除了检查被调用方名称,正常启动外,还要留意服务注册到注册中心需要一定的时间;
2.2,连接拒绝
feign.RetryableException: Connection refused: connect executing GET http://FEEINTE/feeinte/selectAllCi
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.$Proxy92.selectAllCity(Unknown Source)
2.3,连接超时
feign.RetryableException: Connection timed out: connect executing GET http://FEEINTE/feeinte/selectAllCi
at feign.FeignException.errorExecuting(FeignException.java:67)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
3,分析过程:
3.1,当调用失败的时候,把path直接替换为url;确保被调用端服务是正常的;
替换前
@FeignClient(name="FEEINTE",path="/feeinte")
替换后
@FeignClient(name="FEEINTE",url="http://223.70.160.141:1903/feeinte/")
3.2,查看具体报错信息中能体现实际的后台地址
2023-02-24 13:44:36.433 INFO 32373 --- [-nio-443-exec-9] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client FEEINTERFACE initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=FEEINTE,current list of Servers=[223.70.130.141:1903],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:223.70.130.141:1903; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 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@32dc7614
feign.RetryableException: Connection refused (Connection refused) executing GET http://FEEINTE/feeinte/selectAllCi文章来源:https://www.toymoban.com/news/detail-785073.html
3.2.1,根据实际请求地址,排查客户端配置文件;文章来源地址https://www.toymoban.com/news/detail-785073.html
到了这里,关于springboot远程调用常见问题feign.RetryableException: Connection timed out的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!