<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>

                >[warning] Version:`2.4~3.1版本` ,3.2+后切換為Sentinel > [TOC] ## 微服務熔斷/降級/限流——全局配置 jeecg-cloud-gateway 模塊中application.yml加入如下配置 ~~~ # 全局熔斷降級配置 default-filters: - name: Hystrix args: name: default #轉發地址 fallbackUri: 'forward:/fallback' - name: Retry args: #重試次數,默認值是 3 次(負載均衡客戶端發現遠程請求實例不可到達后,去重試其他實例) retries: 3 #HTTP 的狀態返回碼 statuses: BAD_GATEWAY,BAD_REQUEST #指定哪些方法的請求需要進行重試邏輯,默認值是 GET 方法 methods: GET,POST # hystrix 信號量隔離,60秒后自動超時(生成環境根據各自項目情況調整,如需測試請將時間調小點) hystrix: enabled: true command: default: execution: isolation: strategy: SEMAPHORE thread: #超時時間 timeoutInMilliseconds: 60000 ~~~ 熔斷處理器編寫 ~~~ /** * 響應超時熔斷處理器 * * @author zyf */ @RestController public class FallbackController { /** * 全局熔斷處理 * @return */ @RequestMapping("/fallback") public Mono<String> fallback() { return Mono.just("訪問超時,請稍后再試!"); } } ~~~ ## 熔斷路由配置 nacos中json配置,xml配置參考全局配置寫法 ``` [ { "id": "jeecg-cloud-demo", "order": 1, "predicates": [ { "name": "Path", "args": { "_genkey_0": "/api/**", "_genkey_1": "/test/**" } } ], "filters": [ { "name": "Hystrix", "args": { "name": "default", "fallbackUri": "forward:/demo/fallback" } } ], "uri": "lb://jeecg-cloud-demo" } ] ``` filters部分為熔斷配置 ### Spring cloud gateway熔斷不重試問題 ![](https://img.kancloud.cn/fa/fb/fafbfc6a41434b312e7562308e731d1e_1044x678.png) ![](https://img.kancloud.cn/e6/88/e6882ec843d1d669685c521652f2bab4_1036x648.png) ### Spring cloud filters 說明 ![](https://img.kancloud.cn/0a/0b/0a0b7803647526fde7a635b68920bcee_1240x490.png) 部分過濾器說明 ![](https://img.kancloud.cn/64/6e/646eee1970b0984f4cc04ece96b53255_892x814.png) ![](https://img.kancloud.cn/9c/45/9c4555ba59c5d6e520b7755a2803fa54_893x656.png) ![](https://img.kancloud.cn/d4/b2/d4b2d32c322fb6e7462f6a731394bbb0_900x637.png) ![](https://img.kancloud.cn/77/a7/77a7618c30ecfbeb1f9bb3133886bbb6_893x437.png) ![](https://img.kancloud.cn/eb/8d/eb8dcb9f6288ce283ddfe218b82e12e6_898x425.png) ![](https://img.kancloud.cn/49/30/4930fc0ab4374d6ce46899ea07ef9461_909x337.png) [過濾器詳解](https://blog.csdn.net/forezp/article/details/85057268) [ 視頻教程](https://www.bilibili.com/video/BV1sZ4y1G7LL?p=8) ***** #### 限流配置 通過界面配置 限流方式支持IP/用戶接口等方式 ip限流:key-resolver: '#{@ipKeyResolver}' 用戶限流:key-resolver: '#{@userKeyResolver}' 接口限流:key-resolver: '#{@apiKeyResolver}' ![](https://img.kancloud.cn/ff/1a/ff1a1393408dce6263cc9f5fab3ca2ac_775x1238.png) json路由配置 ``` "filters": [{ "name": "RequestRateLimiter", "args": { "key-resolver": "#{@ipKeyResolver}", "redis-rate-limiter.replenishRate": 1, "redis-rate-limiter.burstCapacity": 20 } }] ``` xml路由配置 ``` spring: redis: host: localhost filters: #redis限流, filter名稱必須是RequestRateLimiter - name: RequestRateLimiter args: # 使用SpEL名稱引用Bean,與上面新建的RateLimiterConfig類中的bean的name相同 key-resolver: '#{@ipKeyResolver}' # 每秒最大訪問次數 redis-rate-limiter.replenishRate: 20 # 令牌桶最大容量 redis-rate-limiter.burstCapacity: 20 ``` #### 限流測試 模擬100個并發 ![](https://img.kancloud.cn/52/7f/527f143c239827162b22a91f907ca157_1138x644.png) 測試結果 ![](https://img.kancloud.cn/33/a1/33a1edccd53c91b4eb3deb48e8a53a73_1472x853.png)
                  <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>

                              哎呀哎呀视频在线观看