<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                本文只是簡單的zuul入門,嘗嘗鮮! ## Zuul簡介 Zuul是Netflix開源的微服務網關,它可以和Eureka、Ribbon、Hystrix等組件配合使用。Zuul的核心是一系列的過濾器,這些過濾器幫助我們完成以下功能: * 身份認證與安全:識別每個資源的驗證要求,并拒絕那些與要求不符的請求; * 審查與監控:在邊緣位置追蹤有意義的數據和統計結果,從而為我們帶來精確的生產視圖; * 動態路由:動態地將請求路由到不同的后端集群; * 壓力測試:逐漸增加指向集群的流量,以了解性能; * 負載分配:為每一種負載類型分配對應容量,并棄用超出限定值的請求; * 靜態響應處理:在邊緣位置直接建立部分響應,從而避免其轉發到內部集群; * 多區域彈性:跨越AWS Region進行請求路由,旨在實現ELB(Elastic Load Balancing)使用的多樣化;以及讓系統的邊緣更貼近系統的使用者。 ## 集成zuul 1. 添加依賴 ~~~ <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> ~~~ 2. 添加失敗處理器 ~~~ @Component public class MyFallbackProvider implements FallbackProvider { @Override public String getRoute() { // 表明是為哪個微服務提供回退,*表示為所有微服務提供回退 return "*"; } @Override public ClientHttpResponse fallbackResponse(String route, Throwable cause) { if (cause instanceof HystrixTimeoutException) { return response(HttpStatus.GATEWAY_TIMEOUT); } else { return this.fallbackResponse(); } } public ClientHttpResponse fallbackResponse() { return this.response(HttpStatus.INTERNAL_SERVER_ERROR); } private ClientHttpResponse response(final HttpStatus status) { return new ClientHttpResponse() { @Override public HttpStatus getStatusCode() throws IOException { return status; } @Override public int getRawStatusCode() throws IOException { return status.value(); } @Override public String getStatusText() throws IOException { return status.getReasonPhrase(); } @Override public void close() { } @Override public InputStream getBody() throws IOException { return new ByteArrayInputStream("服務不可用,請稍后再試。".getBytes()); } @Override public HttpHeaders getHeaders() { // headers設定 HttpHeaders headers = new HttpHeaders(); MediaType mt = new MediaType("application", "json", Charset.forName("UTF-8")); headers.setContentType(mt); return headers; } }; } } ~~~ 3. 編寫啟動類,添加注解`@EnableZuulProxy` ~~~ @EnableZuulProxy @SpringBootApplication(scanBasePackages = "com.github.mg0324") public class StartupApplication { public static void main(String[] args) { SpringApplication.run(StartupApplication.class,args); } } ~~~ 4. 添加配置 ~~~ server: port: 8040 eureka: client: service-url: defaultZone: http://192.168.3.26:8761/eureka/ management: endpoints: web: exposure: include: '*' endpoint: health: show-details: always logging: level: com.netflix: DEBUG # 配置路由 zuul: routes: mic-card: path: /card/** strip-prefix: false mic-test: path: /test/** strip-prefix: false #prefix: /gateway ~~~ 5. 啟動mic-card的微服務,并訪問測試 http://127.0.0.1:8040/card/admin/card/rand ![](https://img.kancloud.cn/14/45/14452546342bcf811cda9cc508ba626d_2508x334.png) ![](https://img.kancloud.cn/4d/e4/4de4304a5cf9136e6556ad06f9480911_1492x256.png) ## 總結 * zuul只是spring cloud全家桶里的網關的一種實現,后續還有gateway。 * 其中路由的配置最重要,網關能對路由做相關編排實現。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看