网关 zuul 与 spring-cloud gateway的区别

1510阅读 0评论2021-04-27 fhadmin
分类:Java


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配置:  

#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: 
zuul:
  routes:
    zuul-path:
      path: /zuul-path/**
#连接:

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配置:

#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
#连接:地址/请求路径?参数

zuul1与spring-cloud-gateway的区别:

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

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



上一篇:Java 读取 Word 文本中的标题
下一篇:Oracle创建表空间和用户