摘要:主要是总结了一下这段时间在使用 feign 的过程中的遇到的一些坑点。
一、get请求自动转化成post的问题
1、client 请求参数没有加上 @requestparam 注解
问题代码:
@getmapping(/showname)string showname(string name);
错误提示:
[{timestamp:2022-12-14t0922.370+00:00,status:405,error:method not allowed,path:/showname}]
修改建议:
在对应的请求参数上加上 @requestparam 注解,代码示例如下所示:
@getmapping(/showname)string showname(@requestparam(name) string name);
2、client 请求参数中使用了 @requestbody 注解
问题代码:
@getmapping(/showbody)string showbody(@requestbody string body);
错误提示:
[{timestamp:2022-12-14t1008.943+00:00,status:405,error:method not allowed,path:/showbody}]
原因:
okhttp 和 httpurlconnection 不支持 @requestbody + requestmethod.get,只有 httpclient 支持,默认使用 httpurlconnection。
修改建议:
1、最佳建议:要求提供方,更改为post请求
2、使用 httpclient
引入 httpclient 包
io.github.openfeign feign-httpclient
修改配置:
feign.httpclient.enabled = true
二、feign hystrix 熔断、线程使用坑点
hystrx 官方配置解释地址:
https://github.com/netflix/hystrix/wiki/configuration
线程池队列配置问题
常用配置:
# 核心线程池大小,默认值为:10hystrix.threadpool.default.coresize = 10# 调用超时时间,默认值为 1000mshystrix.command.default.execution.isolation.thread.timeoutinmilliseconds = 15000# 最大线程池大小,这是在不开始拒绝的情况下可以支持的最大并发量。默认值为10。hystrix.threadpool.default.maximumsize = 50# 队列大小拒绝阈值,默认值为 5。即使 maxqueuesize 未达到也会发生拒绝。在 maxqueuesize == -1 时不生效。hystrix.threadpool.default.queuesizerejectionthreshold = 100# maximumsize 配置是否生效,默认值为 false。maximumsize 可以等于或高于 coresize。# 设置 coresize < maximumsize 创建一个可以维持maximumsize并发性的线程池;# 但会在相对不活动期间将线程返回给系统。(受限于keepalivetimeinminutes)。hystrix.threadpool.default.allowmaximumsizetodivergefromcoresize = true# 最大队列大小,默认值为 -1。值为-1时:使用 thensynchronousqueue;值为正值时:使用 linkedblockingqueue。hystrix.threadpool.default.maxqueuesize = 50
错误配置①:
hystrix.command.default.execution.isolation.thread.timeoutinmilliseconds=1000
feign使用的是懒加载,第一次调用时,会初始化各种bean,速度很慢,默认1秒很容易超时。
错误配置②:
hystrix.threadpool.default.coresize = 10hystrix.threadpool.default.maxqueuesize = 1000hystrix.threadpool.default.queuesizerejectionthreshold = 20
因为 queuesizerejectionthreshold 太小,实际上在并发达到 30 以上的时候,就会拒绝后面的请求了。
错误配置③:
hystrix.threadpool.default.coresize = 10hystrix.threadpool.default.maxqueuesize = 20hystrix.threadpool.default.queuesizerejectionthreshold = 1000
因为 maxqueuesize 太小,实际上在并发达到 30 以上的时候,就会拒绝后面的请求了。
面向赌场游戏的嵌入式PC可扩展设计
魔爪Mini-MI体验测评
氮化镓功率晶体管基础
AMD 助力研华为多功能电动汽车充电系统提供支持
小米因估值问题选择取消CDR
feign调用常见问题避坑指南!
飞腾受邀参加Arm云游戏及虚拟化技术沙龙,开启Arm云手机新征程
Adobe宣布将在iPad上推出智能移动版本
GaAs光电子市场动态和未来发展趋势
对比分析Zigbee协议与802.15.4协议的联系与区别
蓝牙耳机什么牌子好,300元真无线蓝牙耳机推荐
福建联通成为国内首个将5G技术等技术应用在智慧水利领域的运营商
全国首个5G产业服务平台在福州马尾上线
入门教程:如何用AWorks点亮一个LED灯
世界顶级AR大会ISMAR首次在中国举办 商汤科技展现“AI+AR”的一天
工业物联网的创新如何到现实中
TÜV莱茵质胜之道——汽车行业意见领袖圆桌交流对话
瞄准双摄人像,HUAWEI nova 2 plus/OPPO R11对比评测
海尔智慧厨房场景升级,获评意大利最佳厨房解决方案
从物理接口转向数字接口 不断发展的设备接口带来新的挑战