网关的核心概念:

  • 路由
  • 谓词
  • 过滤器(11个)
  1. spring:
  2. cloud:
  3. gateway:
  4. enabled: true
  5. discovery:
  6. locator:
  7. enabled: true #开启动态路由
  8. lower-case-service-id: true
  9. routes:
  10. - id: trendsi-trace1
  11. uri: lb://trendsi-trace1
  12. predicates:
  13. - Method=GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE
  14. - Path=/api/tr11ace/**
  15. filters:
  16. - StripPrefix=2
  17. httpclient:
  18. connect-timeout: 100000
  19. max-header-size: 102400
  20. max-initial-line-length: 102400
  21. pool:
  22. acquire-timeout: 20000
  23. max-connections: 5000
  24. max-idle-time: 30s
  25. max-life-time: 30s
  26. name: proxy
  27. type: fixed
  28. response-timeout: 10s
  29. loadbalancer:
  30. retry:
  31. enabled: true
  32. sentinel:
  33. enabled: true
  34. transport:
  35. dashboard: localhost:8858
  36. port: 8719
  37. heartbeat-interval-ms: 1000
  38. filter:
  39. enabled: true
  40. metric:
  41. charset: UTF-8
  42. eager: true
  43. log:
  44. dir: ./logs/${spring.application.name}/sentinel
  45. scg:
  46. fallback:
  47. mode: response
  48. response-status: 200
  49. response-body: "{\"code\":\"11005\",\"message\":\"请求太多了\"}"
  50. xy:
  51. enable: true
  52. mvc-interceptor-enable: true
  53. total-interceptor-enable: false
  54. # websocket:
  55. # proxy-ping: false
  56. # max-frame-payload-length: 10000
  57. # proxy:
  58. # host:
  59. # non-proxy-hosts-pattern:
  60. # password:
  61. # port:
  62. # username:
  63. # ssl:
  64. # close-notify-flush-timeout:
  65. # close-notify-read-timeout:
  66. # default-configuration-type: tcp
  67. # handshake-timeout:
  68. # key-password:
  69. # key-store:
  70. # key-store-password:
  71. # key-store-provider:
  72. # key-store-type:
  73. # trusted-x509-certificates:
  74. # use-insecure-trust-manager: false
  75. # wiretap: true
  76. # refresh:
  77. # enabled: true
  78. management:
  79. endpoints:
  80. web:
  81. exposure:
  82. include: '*'
  83. endpoint:
  84. health:
  85. show-details: always
  86. logging:
  87. level:
  88. org.springframework.cloud.gateway: info
  89. info:
  90. app.name: ${spring.application.name}
  91. li.name: www.li.com
  92. build.artifactId: '@project.artifactId@'
  93. build.version: '@project.version@'
  94. gateway:
  95. config:
  96. black-url-list:
  97. - /asd/asdasd/asdas
  98. - /asd/asdasd/asdas1
  99. - /asd/asdasd/asdas2
  100. black-ip-list:
  101. - 172.10.23.55
  102. - 172.10.23.56
  103. - 172.10.23.57

/module-api/**

StripPrefix=1

1标识转发时过滤/module-api

过滤器

共提供31个过滤器。

谓词

共提供11个谓词。

After

Before

Between

Cookie

Header

Method

Path(常用)

Host

Query

RemoteAddr

Weight

自定义谓词

RoutePredicateFactory

rpc 泛化调用

gateway 开源版本当前转发的是http请求,对于dubbo rpc请求,需要自行研发。

TODO