天天看點

SpringCloud微服務(七)之zuul路由網關概述與使用概述步驟

文章目錄

  • 概述
  • 步驟

概述

  • Zuul包含了對請求的路由和過濾兩個最主要的功能:
  • 其中路由功能負責将外部請求轉發到具體的微服務執行個體上,是實作外部通路統一入口的基礎而過濾器功能則負責對請求的處理過程進行幹預,是實作請求校驗、服務聚合等功能的基礎.Zuul和Eureka進行整合,将Zuul自身注冊為Eureka服務治理下的應用,同時從Eureka中獲得其他微服務的消息,也即以後的通路微服務都是通過Zuul跳轉後獲得.
  • 注意:Zuul服務最終還是會注冊進Eureka
  • 提供=代理+路由+過濾三大功能

步驟

  1. 建立zuul子產品
  2. 導入依賴
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zuul</artifactId>
    <version>1.4.6.RELEASE</version>
</dependency>
           
  1. 配置檔案
server:
  port: 9527

spring:
  application:
    name: springcloud-zuul

eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
  instance:
    instance-id: zuul9527.com
    prefer-ip-address: true


info:
  app.name: kuang-springcloud
  company.name: blog.kuangstudy.com


zuul:
  routes:
    mydept.serviceId: springcloud-provider-dept
    mydept.path: /mydept/**
  ignored-services: "*"  # 不能再使用這個路徑通路了,ignored : 忽略,隐藏全部的~
  prefix: /kuang # 設定公共的字首
           
  1. 編寫主啟動類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableZuulProxy //
public class ZuulApplication_9527 {

    public static void main(String[] args) {
        SpringApplication.run(ZuulApplication_9527.class,args);
    }

}


           

繼續閱讀