Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Spring cloud micro-service distributed cloud architecture Spring Cloud Zuul

Shulou Source: shulou.com Published: 2022-06-02 19:48:23 10月01日 Update

Spring Cloud large enterprise distributed micro service cloud to build B2B2C e-commerce platform source code please add penguin request: 3536247259

POM dependence

Org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-netflix-zuul

Startup class plus: @ EnableZuulProxy annotation

Configuration:

Spring: application: name: zuul-gatewayeureka: client: service-url: defaultZone: http://localhost:9001/eureka/server: port: 9501zuul: routes: # Map the order-server service to the path / my-order/** order-test-route: serviceId: order-server path: / my-order/** # filter the specified url That is, the specified url ignored-patterns:-/ * / order/list # is not routed when the value of hystrix is small Hystrix takes effect when ribbon.ReadTimeout is small Ribbon takes effect # Note: only zuul routing is valid if url is used # if you are using serviceId, you need to use ribbon.ReadTimeout and ribbon.SocketTimeout) hystrix: command: default: execution: timeout: enabled: true isolation: # the execution timeout of the command will be executed back thread: timeoutInMilliseconds: 8000ribbon: ReadTimeout: 10000 # read timeout Time ConnectTimeout: 10000ignored-patterns to ignore the specified API custom filter needs to implement the ZuulFilter API: / * trigger * * @ author Ruan Sheng * @ date on 2018-7-19 21:48 * / @ Componentpublic class TokenFilter extends ZuulFilter {private static final String TOKEN = "token" / * filter type * * @ return * / @ Override public String filterType () {return FilterConstants.PRE_TYPE;} / * * position of the filter in the filter chain * * @ return * / @ Override public int filterOrder () {return FilterConstants.PRE_DECORATION_FILTER_ORDER-1 The filter is executed when the return value is true, while false does not execute the current filter * * @ return * / @ Override public boolean shouldFilter () {return true This filter is triggered when the user visits * * @ return * @ throws ZuulException * / @ Override public Object run () throws ZuulException {RequestContext requestContext = RequestContext.getCurrentContext (); HttpServletRequest request = requestContext.getRequest (); String token = request.getParameter (TOKEN); if (StringUtils.isEmpty (token)) {requestContext.setSendZuulResponse (false) RequestContext.setResponseStatusCode (HttpStatus.SC_UNAUTHORIZED);} return null;}} / * the user triggers * @ author Ruan Sheng * @ date 21:57 on 2018-7-19 * / @ Componentpublic class PostFilter extends ZuulFilter {@ Override public String filterType () {return FilterConstants.POST_TYPE } @ Override public int filterOrder () {return FilterConstants.SEND_RESPONSE_FILTER_ORDER-1;} @ Override public boolean shouldFilter () {return true;} @ Override public Object run () throws ZuulException {RequestContext requestContext = RequestContext.getCurrentContext (); HttpServletResponse resp = requestContext.getResponse (); resp.setHeader ("auth", "test auth"); return null;}}

Tags: Filter time user service time routing enterprise penguin location only command commerce platform interface annotation source code electronic e-commerce type path Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno NVidia Shulou Technology Redmi