feign

feign将rest请求隐藏,伪装成类似springmvc的controller一样,拼接URL等操作交给feign去做

1、引入openfeign的jar包

2、启动类添加注解

@EnableFeignClient

3、写对应的接口

@FeignClient("user-service")
public interface userclient{
    @GetMapping("user/{id}")
    User queryById(@PathVariable("id") Long id);    
}

4、使用的时候直接注入使用

openfeign已经包含了ribbon和Hystrix,不需要导入Hystrix的包

feign的熔断机制

zuul网关 

路由功能简单使用,注意的是放问的时候需要加上匹配的前缀

zuul:
    routes:
        hehe:
             path: /uer-service/**
             url: http://localhost:8081

面向服务的一种配置(拉取服务列表)

引入eureka的依赖,

eureka:
  client:
    service-url:
      defaultZone: http://localhost:10086/eureka
zuul:
  routes:
    haha:
      path: /user-service/**
      serviceId: user-service

黄色部分的简化的配置方式,可以不写。
    user-service: /user/**
下面是默认的形式,zuul会自动拉取
    user-service: /user-service/**
  ignored-service: 需要忽略的服务(集合形式使用 -打头)
    - consumer-service
zuul:
  routes:
    user-service:
      path: /user/**
      serviceId: user-service
      strip-prefix: true //去除前缀user

 

用户的请求到达前端的zuul,接着会匹配path,结果找到对应的服务id,拉去服务列表,通过负载均衡,最后确定服务的实例,注意feign实现里内部的负载均衡

权限控制(zuul过滤器实现)

过滤器类型:前置、后置、错误、路由

过滤器的优先级

要不要过滤

过滤逻辑

 过滤器的生命周期

前置过滤器中可以配置限流,

原文地址:https://www.cnblogs.com/feixiangdecainiao/p/10852314.html