springcloud feign

springCloud 使用feign服务。

  1. springboot启动带上@EnableFeignCleints (系统自动扫描@FeignCleint的类并注册为bean)
  2. 为请求服务的接口带上@FeignCleint(当请求到方法时,被ReflectiveFeign拦截,通过jdk代理之后返回代理对象)
  3. 进行RequestTemplate请求外部服务使用它的client对象,默认请求对象是HttpURLConnection方式,支持httpclient和OKhttpclient 需要对pom.xml进行处理(这里的默认请求居然是post的有点坑,加上@RequestParam参数可以自动识别为get请求)
 <dependency>
    <groupId>com.netflix.feign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>RELEASE</version>
</dependency>

或者

<dependency>
    <groupId>com.netflix.feign</groupId>
    <artifactId>feign-okhttp</artifactId>
    <version>RELEASE</version>
</dependency>

4.feign使用负载均衡策略(默认使用LoadBalancerFeignClient实现),当请求封装完毕之后,通过executeWithLoadBalancer方法进行负载均衡。

参考:https://blog.csdn.net/forezp/article/details/73480304

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值