12

网关 zuul 与 spring-cloud gateway的区别

 3 years ago
source link: https://my.oschina.net/fhadmin/blog/5034164
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
网关 zuul 与 spring-cloud gateway的区别

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

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

yml配置:  

#java www.fhadmin.org
server:
port: 10000

spring:
 application:
	name: user-service-zuul

eureka:
  instance:
    prefer-ip-address: true
    ip-address: 127.0.0.1
  client:
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka:7000/eureka,http://eureka01:7001/eureka,http://eureka02:7002/eureka

zuul:
  routes:
    zuul-path:
      path: /zuul-path/**

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

spring-cloud-gateway:

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

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

yml配置:

#java www.fhadmin.org
# 应用名称
spring:
  application:
    name: ticket-gateway
    
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
        
    gateway:
      routes:
      - id: user-route
        uri: lb://user # 负载均衡方式访问user服务
        predicates: # 匹配条件
          - Path=/api/user/**
        filters:
          - StripPrefix=2
     
# ==>  http://{user地址}/{**代表的实际路径}

# 端口
server:
  port: 10000

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

zuul1与spring-cloud-gateway的区别:

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

2、zuul仅支持同步,
 gateway支持异步。

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK