網關 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編程模型簡單,開發調試運維簡單,有線程數限制,延遲堵塞會耗盡線程連接資源。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章