一、简单说一下目前的系统

1.注册中心shop-eureka

2.网关shop-gateway

3.业务系统shop-business

4.用户服务shop-user-center

二、问题,现在我是在shop-bussiness系统中使用feign调用shop-user-center的接口

1.shop-user-center
在这里插入图片描述
2.shop-business中的feign接口:
在这里插入图片描述

3.shop-business中的feign接口使用
在这里插入图片描述

可以看出在图一中我设置sleep时间为7秒,最开始我自己不设置超时时间,在图上调用的时候肯定是报超时错误:java.util.concurrent.TimeoutException: null。

三、设置超时

1.在shop-gateway的application.properties中添加配置,设置的ReadTimeout是8秒:

ribbon.ReadTimeout=8000

ribbon.ConnectTimeout=6000

测试结果:java.util.concurrent.TimeoutException: null

2.在shop-gateway中application.properties添加配置:

ribbon.ReadTimeout=8000

ribbon.ConnectTimeout=6000

测试结果:java.util.concurrent.TimeoutException: null

3.在调用方shop-business中application.properties添加配置:

ribbon.ReadTimeout=8000

ribbon.ConnectTimeout=6000

测试结果:java.util.concurrent.TimeoutException: null

4.在调用方shop-business中application.properties添加配置:

shop-user-center.ribbon.ReadTimeout=8000

shop-user-center.ribbon.ConnectTimeout=6000

测试结果:成功。

四、总结

1.feign是客户端调用,shop-business是feignclient,所以在shop-business设置超时时间。

五、问题

1.如何设置全局超时时间?

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐