Spring Cloud Spring Zuul

Spring Cloud Zuul

邱誌寬 2019/12/26 10:00:00
1355

簡介

本文將介紹如何使用SpringCloud啟動Zuul服務,進行簡單的配置服務

作者

邱誌寬

1.透過 Spring Initializr 建立 zuul-server project 、 zuul-client1 project 、  zuul-client2 project

   (1)建立zuul-server project

  (2)建立zuul-client1 project

  (3)建立zuul-client3 project

 

2.開啟zuul-server project

  (1)在 ZuulServerApplication.java 加上@EnableEurekaServer、@EnableZuulProxy

  (2)配置文件application.properties

     ribbon.eureka.enabled:在指定url時需設定false
     zuul.routes.client-api.path :匹配/client-api/**,zuul會請求到client-api服務上
     zuul.routes.client-api.url:指定client-api服務
     client-api.ribbon.listOfServers:設定client-api服務的url

 

  (3)啟動zuul-server

3.開啟zuul-client1 project

  (1)在 ZuulClient1Application.java 加上@EnableDiscoveryClient

  (2)建立ZuulClient1Controller.java 

  (3)配置文件application.properties

  (4) 啟動zuul-client1

3.zuul-client2的動作與zuul-client1一樣,完成後就可看到有2台EUREKA-API-CLIENT

4.輸入localhost:8888/client-api/api/index,zuul就隨機路由到其中一台EUREKA-API-CLIENT

 

看到以上畫面就代表成功

參考資料:
    http://www.ityouknow.com/springcloud/2017/06/01/gateway-service-zuul.html
    https://www.cnblogs.com/hellxz/p/9282756.html
     

邱誌寬