OpenFeign

Feign is a Java to HTTP client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal was reducing the complexity of binding Denominator uniformly to HTTP APIs regardless of ReSTfulness.
interface GitHub {
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);

  @RequestLine("POST /repos/{owner}/{repo}/issues")
  void createIssue(Issue issue, @Param("owner") String owner, @Param("repo") String repo);
}

一、注册中心使用

    (1)依赖引用

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

    (2)启动类增加注解@EnableFeignClients

@SpringBootApplication
@EnableFeignClients
public class UserApplicaiton

    (3)编写openfeign接口

@FeignClient(name="order")
public interface OrderFeignInterface {
    @RequestMapping("/order/query")
    String query();
}

    (4)controller使用

@Resource
private OrderFeignInterface orderFeignInterface;

@RequestMapping("/feignquery")
public String feginQuery(){
    return this.orderFeignInterface.query();
}

二、使用

    (1)编写openfeign接口

@FeignClient(name = "jsk",url = "http://127.0.0.1:8081")
public interface SkFeignClient {

    @RequestMapping("/order/query")
    String query();
}

模板如下
@FeignClient(name = "${feign.name}", url = "${feign.url}")
public interface StoreClient {
    //..
}

    (2)controller使用

@Resource
private SkFeignClient skFeignClient;

@RequestMapping("/openfeign-url")
public String openfeignUrl(){
    return this.skFeignClient.query();
}

三、OpenFeign默认值修改:Spring Cloud OpenFeign

    (1)、日志级别修改

    其他方式:配置

logging:
  level:
    com.sk.cloud.user.feign.OrderFeignInterface: DEBUG
feign:
  client:
    config:
      order:#定义服务配置,全局服务配置改成default
        loggerLevel: full

    (2)、http请求方式修改:httpurlconnection --> httpclient

            2.1、依赖引入

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
</dependency>

            2.2、增加配置

feign:
  httpclient:   
    enabled: true
    max-connections: 200
    max-connections-per-route: 50

四、OpenFeign架构

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值