Zuul配置详解

    科技2024-07-04  96

    1.路由中参数path、url和path、serviceId配置区别

    Spring Cloud Zuul默认包含了对Hystrix和Ribbon的依赖,所以Zuul拥有线程隔离和断路器的自我保护功能,以及对客户端的负载均衡能力。但是,需要注意在使用path和url的映射关系来配置路由规则时,对于路由转发的请求不会采用HystrixCommand机制,所以这类路由请求没有线程隔离和断路器的保护以及负载均衡的能力。所以使用Zuul的时候尽量使用path和serviceId的方式配置。

    2.策略选择(Semaphore/ThreadPool)

    3.prefix 和 strip-prefix使用

    prefix :前缀,当请求匹配前缀时会进行代理。strip-prefix :代理前缀默认会从请求路径中移除,通过该设置关闭移除功能。 例如: 1.当 stripPrefix=true 的时 (会移除),默认为true http://127.0.0.1:7001/api/userdemo/list 变为http://192.168.1.100:8080/userdemo/list) 2.当stripPrefix=false的时(不会移除) http://127.0.0.1:7001/api/userdemo/list 变为http://192.168.1.100:8080/api/userdemo/list

    # 将请求/api/userdemo/test 转发到user-demo的 /api/test prefix: /api # 访问网关路径的前缀(在映射路径的前面,一般用于区别开发的版本) strip-prefix: false ##路由代理 routes: user-token: path: /userdemo/** serviceId: user-demo ------------------------------------------------------------------------ # 将请求/api/userdemo/test 转发到user-demo的 /userdemo/test prefix: /api # 访问网关路径的前缀(在映射路径的前面,一般用于区别开发的版本) ##路由代理 routes: user-token: path: /userdemo/** strip-prefix: false serviceId: user-demo

    4.相关调优

    参考链接: 1.http://www.itmuch.com/spring-cloud-sum/spring-cloud-concurrent/ 2.https://www.jianshu.com/p/ebd62bac2ed4 3.https://blog.csdn.net/w1014074794/article/details/88571880

    Processed: 0.009, SQL: 8