SpringCloud Zuul的使用簡(jiǎn)介
簡(jiǎn)介
- Zuul是Spring Cloud全家桶中的微服務(wù)API網(wǎng)關(guān)。 所有從設(shè)備或網(wǎng)站來的請(qǐng)求都會(huì)經(jīng)過Zuul到達(dá)后端的Netflix應(yīng)用程序
- Zuul 主要提供路由(請(qǐng)求轉(zhuǎn)發(fā))和過濾
- Zuul 最終會(huì)注入Eureka
提供: 代理,過濾和路由三大功能
使用
導(dǎo)入依賴
<!--zuul組件、zuul需要注冊(cè)至eureka中-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
配置文件
server:
port: 9527
spring:
application:
name: springcloud-zuul
eureka:
client:
service-url:
defaultZone: http://eureka1:7001/eureka/,http://eureka2:7002/eureka/,http://eureka3:7003/eureka/
instance:
instance-id: zull9527.com #別名
開啟支持
@SpringBootApplication
@EnableZuulProxy//開啟zuul支持,默認(rèn)注冊(cè)到Eureka
public class Zuul9527Application {
public static void main(String[] args) {
SpringApplication.run(Zuul9527Application.class,args);
}
}
此時(shí)我們可以通過 地址:端口號(hào)/服務(wù)名稱/服務(wù) 來訪問了
注意:此處需在host文件添加 127.0.01 www,zuultest.com

為了不使我們的服務(wù)名稱暴露我們可以在配置文件中添加
zuul:
routes:
xxx.serviceId: provider-name # xxx代表任意名稱
xxx.path: /mydept/**
ignored-services: provider-name # 不再通過這個(gè)路徑訪問即不允許通過服務(wù)名直接訪問
prefix: /lin # 訪問路徑必須加上前綴/lin
此時(shí)只有通過 地址:端口號(hào)/lin/mydept/服務(wù) 來訪問

補(bǔ)充: 為什么在配置文件中是使用serviceId和path 在zull中route是以鍵值對(duì)的形式存放的
public void setRoutes(Map<String, ZuulRoute> routes) {
this.routes = routes;
}
而在ZuulProperties中
/**
* Represents a Zuul route.
*/
public static class ZuulRoute {
/**
* The path (pattern) for the route, e.g. /foo/**.
*/
private String path;
/**
* The service ID (if any) to map to this route. You can specify a physical URL or
* a service, but not both.
*/
private String serviceId;
}
以上就是SpringCloud Zuul的使用簡(jiǎn)介的詳細(xì)內(nèi)容,更多關(guān)于SpringCloud Zuul的使用的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- SpringCloud之Zuul網(wǎng)關(guān)原理及其配置講解
- SpringCloud網(wǎng)關(guān)(Zuul)如何給多個(gè)微服務(wù)之間傳遞共享參數(shù)
- SpringCloud Zuul實(shí)現(xiàn)負(fù)載均衡和熔斷機(jī)制方式
- SpringCloud如何實(shí)現(xiàn)Zuul集群(負(fù)載均衡)
- SpringCloud zuul 網(wǎng)關(guān)如何解決跨域問題
- 解決springcloud Zuul丟失Cookie的問題
- SpringCloud Zuul基本使用方法匯總
- SpringCloud Zuul服務(wù)功能與使用方法解析
- SpringCloud超詳細(xì)講解微服務(wù)網(wǎng)關(guān)Zuul基礎(chǔ)
相關(guān)文章
重新認(rèn)識(shí)Java中的ThreadLocal
ThreadLocal是JDK包提供的,它提供線程本地變量,如果創(chuàng)建一個(gè)ThreadLocal變量,那么訪問這個(gè)變量的每個(gè)線程都會(huì)有這個(gè)變量的一個(gè)副本,在實(shí)際多線程操作的時(shí)候,操作的是自己本地內(nèi)存中的變量,從而規(guī)避了線程安全問題2021-05-05
Spring boot + mybatis + orcale實(shí)現(xiàn)步驟實(shí)例代碼講解
這篇文章主要介紹了Spring boot + mybatis + orcale的實(shí)現(xiàn)步驟實(shí)例代碼講解,需要的朋友可以參考下2017-12-12
解決java.lang.ClassNotFoundException: com.mysql.cj.jdbc.D
這篇文章主要介紹了解決java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
springboot整合mybatis-plus實(shí)現(xiàn)多表分頁(yè)查詢的示例代碼
這篇文章主要介紹了springboot整合mybatis-plus實(shí)現(xiàn)多表分頁(yè)查詢的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
JAVA實(shí)現(xiàn)JSON后端向前端傳遞數(shù)據(jù)
本篇文章主要介紹了JAVA實(shí)現(xiàn)JSON后端向前端傳遞數(shù)據(jù),這里整理了詳細(xì)的代碼,具有一定的參考價(jià)值,有需要的小伙伴可以參考下。2017-03-03
Java基礎(chǔ)學(xué)習(xí)之方法的重載知識(shí)總結(jié)
今天帶大家來回顧Java基礎(chǔ)知識(shí),文中對(duì)Java方法的重載相關(guān)知識(shí)作了非常詳細(xì)的介紹,對(duì)正在學(xué)習(xí)java的小伙伴們有很好的幫助,需要的朋友可以參考下2021-05-05
Java動(dòng)態(tài)調(diào)用類中方法代碼
這篇文章主要介紹了Java動(dòng)態(tài)調(diào)用類中方法代碼,需要的朋友可以參考下2014-02-02

