小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Spring Cloud Gateway 使用

 文炳春秋 2020-03-13

簡介

Spring Cloud Gateway 是 Spring Cloud 官方推出的網(wǎng)關框架,網(wǎng)關作為流量入口,在微服務系統(tǒng)中有著十分重要的作用,常用功能包括:鑒權、路由轉發(fā)、熔斷、限流等。

Spring Cloud Gateway 是通過 Spring WebFlux 的 HandlerMapping 做為底層支持來匹配到轉發(fā)路由,使用時不要引入 SpringMVC,否則初始化時會出錯;Spring Cloud Gateway 內(nèi)置了很多 Predicates工廠,這些 Predicates 工廠通過不同的 HTTP 請求參數(shù)來匹配,多個 Predicates 工廠可以組合使用。

快速上手

1)添加依賴

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

2)配置(結合Eureka使用)

server:
  port: 8066
spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true  #設置serviceId小寫,默認大寫
      routes:
      - id: user-server
        uri: lb://user-server   #lb表示從注冊中心獲取服務
        predicates:
        - Path=/userapi/**         # 如果請求地址滿足/userapi/**,則轉發(fā)到user-server服務
        filters:
        - StripPrefix=1           # 去除原請求地址中的userapi
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8088/eureka/

3)集成Hystrix

添加依賴

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

添加配置

filters:
- name: Hystrix
  args:
    name : default
    fallbackUri: 'forward:/dfallback'
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 6000

4)Java 端

@RestController
public class DHystrixController {
    @RequestMapping("/dfallback")
    public Map<String,String> dfallback(){
        System.out.println("降級了。。。");
        Map<String,String> map = new HashMap<String,String>();
        map.put("rCode","-1");
        map.put("rMsg","出錯了");
        return map;
    }
}


    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多