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

Brief introduction to the use of zuul

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Several configuration parameters of zuul routing

1. Static rout

Zuul:

Routes:

Myroute1:

Path: / mypath/**

Url: http://localhost:8080 (note that url starts with http://)

two。 Static routing + ribbon load balancing / failover

Zuul:

Routes:

Myroutes1:

Path: / mypath/**

ServiceId: myserverId

MyserverId:

Ribbon:

ListOfServers: localhost:8080, localhost:8081

Ribbon:

Eureka:

Enabled: false

3. Dynamic routing + ribbon load balancing / failover

Zuul:

Routes:

Myroutes1:

Path: / mypath/**

ServiceId: myserviceId

Eureka:

Client:

ServiceUrl:

DefaultZne:xxx

4. Some configurations for route matching

StripPrefix=true, forwarding will filter out the prefix.

Path: / myusers/**, by default, the request forwarded to the service is / * *, if stripPrefix=false, the forwarded request is / myusers/**

Zuul.prefix=/api adds a / api prefix to all path

IgnoredPatterns: / * * / admin/** filter out matching url

Route:

Users: / myusers/** will match all url of / myusers/**, but since the request of ignoredPatterns / myusers/**/admin/** will not be forwarded, it will be received directly by the interface in zuul.

Matching order

Path:/myusers/**

If path:/** is configured in application.yml, it will match / myusers/** first.

But if it is configured by applicaiton.properties, it may cause / myusers/** to be overwritten by / *

Ignored-Services:'* 'all automatically discovered services will be ignored except those explicitly specified in route

5. Request header filtering

Route.sensitiveHeaders: Cookie,Set-Cookie,Authorization

There are these three request headers by default, which means that the request headers are not forwarded downstream.

Zuul.ignoredHeaders is a global setting, while route.sensitiveHeaders is a local setting zuul filter

There are 4 standard zuul filters, which correspond to several key points of a route forwarding.

Pre: works before routing is forwarded

Routing: its role in routing

Post: works when returning the results to the browser

Error: works when an exception occurs throughout the routing phase

If you want to analyze the front-end parameters, verify the front-end identity and other operations on the front-end parameters, it is obvious to use the pre filter

If you want to manipulate or analyze the results returned to the front end, you obviously use the post filter

Write a custom router

Public class MyFilter extends ZuulFilter {

FilterType () override to return the type of this filter

FilterOrder () override to return the order of the filter in the filter chain

ShouldFilter () true start

Run () concrete logic

}

And then inject this Bean into Spring.

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