SpringCloud Zuul服務(wù)功能與使用方法解析
Zuul是什么?
Zuul包含了對請求的路由和過濾兩個最主要的功能:
其中路由功能負責(zé)將外部請求轉(zhuǎn)發(fā)到具體的微服務(wù)實例上,是實現(xiàn)外部訪問統(tǒng)一入口的基礎(chǔ)而過濾器功能則負責(zé)對請求的處理過程進行干預(yù),是實現(xiàn)請求校驗、服務(wù)聚合等功能的基礎(chǔ).
Zuul和Eureka進行整合,將Zuul自身注冊為Eureka服務(wù)治理下的應(yīng)用,同時從Eureka中獲得其他微服務(wù)的消息,也即以后的訪問微服務(wù)都是通過Zuul跳轉(zhuǎn)后獲得.
注意:Zuul服務(wù)最終還是會注冊進Eureka
提供=代理+路由+過濾三大功能
•創(chuà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 #顯示真實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í)有所幫助,也希望大家多多支持腳本之家。
- SpringCloud之Zuul網(wǎng)關(guān)原理及其配置講解
- SpringCloud網(wǎng)關(guān)(Zuul)如何給多個微服務(wù)之間傳遞共享參數(shù)
- SpringCloud Zuul實現(xiàn)負載均衡和熔斷機制方式
- SpringCloud如何實現(xiàn)Zuul集群(負載均衡)
- SpringCloud zuul 網(wǎng)關(guān)如何解決跨域問題
- SpringCloud Zuul的使用簡介
- 解決springcloud Zuul丟失Cookie的問題
- SpringCloud Zuul基本使用方法匯總
- SpringCloud超詳細講解微服務(wù)網(wǎng)關(guān)Zuul基礎(chǔ)
相關(guān)文章
idea快捷鍵生成getter和setter,有構(gòu)造參數(shù),無構(gòu)造參數(shù),重寫toString方式
這篇文章主要介紹了java之idea快捷鍵生成getter和setter,有構(gòu)造參數(shù),無構(gòu)造參數(shù),重寫toString方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
SpringMVC接收復(fù)雜集合對象(參數(shù))代碼示例
這篇文章主要介紹了SpringMVC接收復(fù)雜集合對象(參數(shù))代碼示例,舉接收List<String>、List<User>、List<Map<String,Object>>、User[]、User(bean里面包含List)幾種較為復(fù)雜的集合參數(shù),具有一定參考價值,需要的朋友可以了解下。2017-11-11
Java的JSON轉(zhuǎn)換庫GSON的基本使用方法示例
GSON是Google制作的一個可以讓Java對象與JSON互相轉(zhuǎn)換的類庫,下面我們就來看一下Java的JSON轉(zhuǎn)換庫GSON的基本使用方法示例:2016-06-06
springboot整合spring-data-redis遇到的坑
使用springboot整合redis,使用默認的序列化配置,然后使用redis-client去查詢時查詢不到相應(yīng)的key.問題出在哪,怎么解決呢?下面小編給大家?guī)砹藄pringboot整合spring-data-redis遇到的坑,需要的的朋友參考下吧2017-04-04

