欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

springcloud如何構建微服務架構的網(wǎng)關

這篇文章主要為大家展示了“spring cloud如何構建微服務架構的網(wǎng)關”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“spring cloud如何構建微服務架構的網(wǎng)關”這篇文章吧。

創(chuàng)新互聯(lián)是專業(yè)的公主嶺網(wǎng)站建設公司,公主嶺接單;提供成都做網(wǎng)站、成都網(wǎng)站制作,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行公主嶺網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

一、加入Zuul的依賴

<dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-zuul</artifactId> 
    </dependency> 
    <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-eureka</artifactId> 
    </dependency>

由于,我們需要將Zuul服務注冊到Eureka Server上,同時從Eureka Server上發(fā)現(xiàn)注冊的服務,所以這里我們加上了Eureka的依賴。

二、在應用Application主類上開啟Zuul支持

@SpringBootApplication 
@EnableZuulProxy // 使用@EnableZuulProxy來開啟Zuul的支持,如果你不想使用Zuul提供的Filter和反向代理的功能的話,此處可以使用@EnableZuulServer注解 
public class ZuulApplication { 
 public static void main(String[] args) { 
  SpringApplication.run(ZuulApplication.class, args); 
 } 
}

三、在application.yml中增加Zuul的基礎配置信息

spring: 
 application: 
  name: gateway-zuul # 應用名 
server: 
 port: 8768 #Zuul Server的端口號 
eureka: 
 client: 
  service-url: 
   defaultZone: http://localhost:8761/eureka 
 instance: 
  prefer-ip-address: true

四、在application.yml中增加服務路由配置

前提:在Eureka Server已經(jīng)注冊了2個服務,分別是:springboot-h3-service和springboot-rest-template-feign,其中springboot-rest-template-feign服務會調(diào)用springboot-h3-service服務,springboot-rest-template-feign服務是我們對外提供的服務,也就是說,springboot-rest-template-feign服務是我們暴漏給客戶端調(diào)用的。

# 路由配置方式一 
#zuul: 
# routes: 
#  springboot-rest-template-feign: /templateservice/** #所有請求springboot-rest-template-feign的請求,都會被攔截,并且轉(zhuǎn)發(fā)到templateservice上 
 
 
# 路由配置方式二 
zuul: 
 routes: 
  api-contract: # 其中api-contract是路由名稱,可以隨便定義,但是path和service-id需要一一對應 
   path: /templateservice/** 
   service-id: springboot-rest-template-feign # springboot-rest-template-feign為注冊到Eureka上的服務名 
ribbon: 
 NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule # 配置服務端負載均衡策略

五、驗證

下面我們就可以來進行驗證了,在瀏覽器中輸入:http://localhost:8768/templateservice/template/1就可以看到測試結果了。

以上是“spring cloud如何構建微服務架構的網(wǎng)關”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:springcloud如何構建微服務架構的網(wǎng)關
文章出自:http://chinadenli.net/article2/gdgsic.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google云服務器手機網(wǎng)站建設用戶體驗搜索引擎優(yōu)化網(wǎng)站導航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設公司