创建自定义的Zuul过滤器 [英] Creating custom Zuul filters

查看:254
本文介绍了创建自定义的Zuul过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的Zuul代理实现自定义过滤器.现在,我知道有很多关于该主题的话题

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.

我有一台Eureka服务器,注册了3个单独的服务,其中一个是通往其他两个服务的大门,并从每个服务中收集信息并进行检索.

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.

我想做的是重新路由Zuul在流程开始时收到的请求,使用URL参数确定应该针对哪个流程而不是另一个流程,从而通过特定的服务重定向它们. 我已经创建了一个标记为@Component的过滤器,实现了ZuulFilter.我不知道的是如何使重定向有效,以及使用哪种方法.

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.

因此,问题是:如何使用URL参数将传入的请求重定向到其他注册的服务?

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

推荐答案

查看

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.

这篇关于创建自定义的Zuul过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆