Chinaunix首页 | 论坛 | 博客
  • 博客访问: 550855
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-08-03 12:42:02

zuul1与spring-cloud-gateway的区别
Zuul: 
是netflix公司的项目,本质上是web servlet,基于JavaEE Servlet技术栈,使用阻塞API,处理的是http请求,没有提供异步支持,不支持任何长连接,比如websocket。

依赖:

点击(此处)折叠或打开

  1. <dependency>
  2.         <groupId>org.springframework.cloud</groupId>
  3.         <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
  4.     </dependency>
yml配置:

点击(此处)折叠或打开

  1. #java fhadmin.cn
  2. server:
  3. port: 10000

  4. spring:
  5.  application:
  6.     name: user-service-zuul

  7. eureka:
  8.   instance:
  9.     prefer-ip-address: true
  10.     ip-address: 127.0.0.1
  11.   client:
  12.     register-with-eureka: true
  13.     service-url:
  14.       defaultZone: http://eureka:7000/eureka,http://eureka01:7001/eureka,http://eureka02:7002/eureka

  15. zuul:
  16.   routes:
  17.     zuul-path:
  18.       path: /zuul-path/**

  19. #连接:http://localhos:10000/zuul-path/findUserInfo/1

spring-cloud-gateway:

Spring Boot和Spring Webflux提供的Netty底层环境,不能和传统的Servlet容器一起使用,也不能打包成一个WAR包,使用非阻塞API,支持websocket。

依赖:

点击(此处)折叠或打开

  1. <dependency>
  2.         <groupId>org.springframework.cloud</groupId>
  3.         <artifactId>spring-cloud-starter-gateway</artifactId>
  4.     </dependency>
yml配置:

点击(此处)折叠或打开

  1. #java fhadmin.org
  2. # 应用名称
  3. spring:
  4.   application:
  5.     name: ticket-gateway
  6.     
  7.   cloud:
  8.     nacos:
  9.       discovery:
  10.         server-addr: localhost:8848
  11.         
  12.     gateway:
  13.       routes:
  14.       - id: user-route
  15.         uri: lb://user # 负载均衡方式访问user服务
  16.         predicates: # 匹配条件
  17.           - Path=/api/user/**
  18.         filters:
  19.           - StripPrefix=2
  20.      
  21. # ==> http://{user地址}/{**代表的实际路径}

  22. # 端口
  23. server:
  24.   port: 10000

  25. #连接:http://ip地址/请求路径?参数

zuul1与spring-cloud-gateway的区别:

1、gateway对比zuul多依赖了spring-webflux,内部实现了限流、负载均衡等,扩展性也更强,但同时也限制了仅适合于Spring Cloud套件。
zuul则可以扩展至其他微服务框架中,其内部没有实现限流、负载均衡等。
  
2、zuul仅支持同步,
 gateway支持异步。

3、gateway线程开销少,支持各种长连接、websocket,spring官方支持,但运维复杂,
zuul编程模型简单,开发调试运维简单,有线程数限制,延迟堵塞会耗尽线程连接资源。




阅读(777) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~