Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring cloud micro-service distributed cloud architecture Spring Cloud Zuul

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report