Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

spring - Creating custom Zuul filters

I want to implement custom filters for my Zuul proxy. Now, I know there has been a lot of talking about that subject here and I took a look at the answer provided, with the examples of filters and the Spring Cloud documentation, which I went through several times. I have tried to copy some of the filters content to my use, but it didn't work.

I have a Eureka server, registering 3 separate services, one of them being the front door to the other two, collecting information from each of them and retrieving it.

What I want to be able to do is re-route the requests that Zuul receives at the beginning of the process, to redirect them through particular services, using URL parameters to determine which process should be aimed instead of another. I already have created a filter tagged with the @Component annotation, implementing ZuulFilter. What I don't know, is how to make the redirections work, and which methods to use.

So, the question is : How can I redirect incoming requests to different registered services, using URL parameters ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Look at PreDecorationFilter for an example that matches routes based on the url path (ie /myservice). If it matches a full url it sets the routeHost in the ribbon context, otherwise it sets serviceId (which would use ribbon to route). You would need to write something similar that would match on parameter instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...