1、网关zuul常见问题

  • 跨域访问问题

  • token不向后传

  • 老项目中改造路由问题
    image-20201214200958192

2、提高qps和tps

image-20201210160734259

3、使用的技术点

  • springboot、springcloud
  • 微服务:高内聚、低耦合
  • 二方库:公司内部设计的通用工具
  • 三方库:其他公司设计的通用工具
  • eureka有效的服务集群只有三个,注册多个eureka服务无效,只会浪费资源。可以在配置url时打乱url顺序可以有效平衡压力。

4、网关四种过滤器类型

  • 类型

    • pre
    • route
    • post
    • error

    image-20201214193448083

  • 四种过滤器类型执行流程:
    image-20201214193247646

5、实现一个自定义网关过滤器:

  • 继承zuulFilter类

  • 重写shouldFilter,返回Boolean,设置是否执行过滤,true为执行,flase为不执行

    • 重写run,实现过滤器具体的业务逻辑
  • 重写filterType,返回过滤器类型,设置当前过滤器的类型(pre,route,post,error)

  • 重写order,返回int,数字越小越先执行

    image-20201214193628019
    image-20201214200308608

6、路由端点

  • 查看路由端点
    yum文件中配置:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    management:
    endpoints:
    web:
    exposure:
    include: "*"
    endpoint:
    health:
    ##默认是never
    show-details: ALWAYS
    enabled: true
    routes:
    enabled: true
    访问:http://localhost:port/actuator/routes 可以查看eureka中的路由
  • 过滤器端点
    访问:http://localhost:port/actuator/filters 可以查看默认的和自己定义的过滤器