欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud Zuul服務(wù)功能與使用方法解析

 更新時間:2020年05月01日 09:47:02   作者:春天春天  
這篇文章主要介紹了SpringCloud Zuul服務(wù)功能與使用方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

Zuul是什么?

  Zuul包含了對請求的路由和過濾兩個最主要的功能:

    其中路由功能負(fù)責(zé)將外部請求轉(zhuǎn)發(fā)到具體的微服務(wù)實(shí)例上,是實(shí)現(xiàn)外部訪問統(tǒng)一入口的基礎(chǔ)而過濾器功能則負(fù)責(zé)對請求的處理過程進(jìn)行干預(yù),是實(shí)現(xiàn)請求校驗(yàn)、服務(wù)聚合等功能的基礎(chǔ).

Zuul和Eureka進(jìn)行整合,將Zuul自身注冊為Eureka服務(wù)治理下的應(yīng)用,同時從Eureka中獲得其他微服務(wù)的消息,也即以后的訪問微服務(wù)都是通過Zuul跳轉(zhuǎn)后獲得.

  注意:Zuul服務(wù)最終還是會注冊進(jìn)Eureka

  提供=代理+路由+過濾三大功能

  •創(chuàng)建項(xiàng)目,添加依賴

<dependencies>
    <!--zuul-->
    <!--erueka-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-zuul</artifactId>
      <version>1.4.6.RELEASE</version>
    </dependency>  //Zuul依賴
    <!--Hystrix依賴~-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix</artifactId>
      <version>1.4.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
      <version>1.4.6.RELEASE</version>
    </dependency>
    <!--Ribbon-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-ribbon</artifactId>
      <version>1.4.6.RELEASE</version>
    </dependency>
    <!--erueka-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka</artifactId>
      <version>1.4.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>com.kuang</groupId>
      <artifactId>springcloud-api</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
    </dependency>
  </dependencies>

  •編寫application.yml配置

server:
 port: 9527

spring:
 application:
  name: springcloud-zuul #微服務(wù)注冊的名字
eureka:
 client:
  service-url:
   defaultZone: http://localhost:7001/eureka/,http://localhost:7002/eureka/,http://localhost:7003/eureka/ #去三個集群中發(fā)現(xiàn)其它服務(wù)
 instance:
  instance-id: zuul9527.com
  prefer-ip-address: true #顯示真實(shí)ip
info:
 app.name: kuang-springcloud
 company.name: blog.kuangstudy.com

zuul:
 routes:
  mydept.serviceId: springcloud-provider-dept #原來需要這個訪問
  mydept.path: /mydept/** #替代上面訪問
 ignored-services: springcloud-provider-dept #忽略,不能再使用這個路徑訪問。
 #ignored-services: "*" 隱藏全部服務(wù)
 prefix: /kuang #設(shè)置公共訪問前綴

  •去hosts里面添加一個本地ip         //看自己選擇

  •開啟功能  

@EnableZuulProxy

  •測試


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論