study-micro-services/study-micro-services-zuul at master · bage2014/study-micro-services · GitHub
Skip to content

Latest commit

 

History

History

study-micro-services-zuul

Folders and files

README.md

study-micro-services-zuul

参考链接

Netflix uses Zuul for the following:

  • Authentication 授权验证
  • Insights
  • Stress Testing 压力测试
  • Canary Testing 金丝雀测试(灰度测试)
  • Dynamic Routing 动态路由
  • Service Migration
  • Load Shedding
  • Security 安全
  • Static Response handling 静态资源
  • Active/Active traffic management

默认路由规则:

  • By convention, a service with an ID of users receives requests from the proxy located at /users (with the prefix stripped). 即 在无任何配置下,默认路由为:网关服务/serviceID/** 路由到 serviceID服务下
  • These simple url-routes do not get executed as a HystrixCommand, nor do they load-balance multiple URLs with Ribbon. To achieve those goals, you can specify a serviceId with a static list of servers
  • You can provide a convention between serviceId and routes by using regexmapper

ApplicationConfiguration.java

 @Bean
public PatternServiceRouteMapper serviceRouteMapper() {
return new PatternServiceRouteMapper(
"(?<name>^.+)-(?<version>v.+$)",
"${version}/${name}");
}

The preceding example means that a serviceId of myusers-v1 is mapped to route /v1/myusers/**

  • Disable Zuul Filters

  • Providing Hystrix Fallbacks For Routes 请求超时时候回调

  • Zuul Timeouts

  • 常用自定义配置

所在包路径:

com.bage.study.micro.services.zuul
	filters
	provider
  • 内置Filter

In addition to the filters described earlier, the following filters are installed (as normal Spring Beans):

  • Pre filters:

  • PreDecorationFilter: Determines where and how to route, depending on the supplied RouteLocator. It also sets various proxy-related headers for downstream requests.

  • Route filters:

    • RibbonRoutingFilter: Uses Ribbon, Hystrix, and pluggable HTTP clients to send requests. Service IDs are found in the RequestContext attribute, FilterConstants.SERVICE_ID_KEY. This filter can use different HTTP clients:
      • Apache HttpClient: The default client.
      • Squareup OkHttpClient v3: Enabled by having the com.squareup.okhttp3:okhttp library on the classpath and setting ribbon.okhttp.enabled=true.
      • Netflix Ribbon HTTP client: Enabled by setting ribbon.restclient.enabled=true. This client has limitations, including that it does not support the PATCH method, but it also has built-in retry.
    • SimpleHostRoutingFilter: Sends requests to predetermined URLs through an Apache HttpClient. URLs are found in RequestContext.getRouteHost().

项目模块说明

网关