简体   繁体   English

我可以仅使用Zuul帖子过滤器获取请求的响应时间吗?

[英]Can I get the request's response time using only a Zuul post filter?

I'm currently using Zuul as a reverse proxy, Ribbon as a load balancer and Eureka as service discovery. 我当前使用Zuul作为反向代理,使用Ribbon作为负载平衡器,并使用Eureka作为服务发现。

Is it possible to get the request's response time using only a Zuul post filter? 是否可以仅使用Zuul帖子过滤器来获取请求的响应时间? Can I also get the timestamps of a request entering and leaving the gateway? 我还能获得进入和离开网关的请求的时间戳吗?

i guess thats possible, but it would involve combination of filters, restTemplate interceptor and servlet Filter classes 我想那是可能的,但它将涉及过滤器,restTemplate拦截器和Servlet过滤器类的组合

i wud have given the diagram had their been a plantuml plugin for stackoverflow 我会给图,如果他们是一个plantuml的stackoverflow插件

idea is , create a preFilter lets say TimeTrackerFilter that would add entry point time stamp "time-start-id" in the request header, a userContextFilter which will intercept all incoming HTTP request and map HTTP request to a userContext class , UserContextClass consists of a getter/setter method that retrieves and stores values from java.lang.ThreadLocal 想法是,创建一个preFilter,让它说TimeTrackerFilter,它将在请求标头中添加入口点时间戳“ time-start-id”;一个userContextFilter,它将拦截所有传入的HTTP请求并将HTTP请求映射到userContext类,UserContextClass由一个用于从java.lang.ThreadLocal检索和存储值的getter / setter方法

UserContextHolder.java to store the UserContext in a ThreadLocal variable that is accessible in any method being invoked by the thread processing the user's request UserContextHolder.java将UserContext存储在ThreadLocal变量中,该变量可以在处理用户请求的线程调用的任何方法中访问

UserContextINterceptor class to inject the "time-start-id" to any outgoing http based service request executed from a rest template UserContextINterceptor类,用于将“ time-start-id”注入到从rest模板执行的所有基于HTTP的传出服务请求中

a post filter that will actually get the time-start-id from request context, calculate time diff and add a new header "time taken " with value being time diff to the response 一个后置过滤器,该过滤器实际上将从请求上下文中获取time-start-id,计算时间差异,并在响应中添加一个新的标头“ time take”,其值为time diff

in case you dont want to see the start time id in other services being called, using only pre and post filter should suffice (ignore userContext, and interceptors in that case) 如果您不想看到正在调用的其他服务中的开始时间ID,则仅使用前置和后置过滤器就足够了(在这种情况下,请忽略userContext和拦截器)

note : when you want to add a value to the HTTP request headers, you use the RequestContext's addZuulRequestHeader() method. 注意 :当您想向HTTP请求标头添加值时,可以使用RequestContext的addZuulRequestHeader()方法。 This method will maintain a separate map of HTTP headers that were added while a request was flowing through the filters with your Zuul server. 此方法将维护一个单独的HTTP标头映射,该映射在请求通过Zuul服务器流经过滤器时添加。 The data con- tained within the ZuulRequestHeader map will be merged when the target service is invoked by your Zuul server. 当您的Zuul服务器调用目标服务时,ZuulRequestHeader映射中包含的数据将被合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Zuul 后置过滤器中获取响应正文? - How to get response body in Zuul post filter? 如何使用zuul将响应主体提取到后过滤器中 - How to extract the response body into post filter using zuul 如何在 Zuul 后置过滤器中拦截和编辑响应正文? - How to intercept and edit response body in Zuul post filter? 在Java的BrowserMob中仅获取POST请求/响应 - Get only POST request/response in BrowserMob in Java 我无法获得POST请求的响应,如果尝试从响应中获取任何信息,它将卡住并超时 - I can't get the response for my POST request, if I try to get anything from the response it will get stuck and timeout 如何使用 ZUUL 处理多个服务的 POST 请求 - How to handle POST request using ZUUL for multiple services 我如何发出HTTP POST请求并使用我应该在android中获得的Json响应 - How can i make an HTTP POST request and and use the Json Response i should get in android 如何自定义Volley库以将发布请求作为Java对象进行获取以作为Java对象获得响应 - How can I Customize Volley Library to make post request as java object to get response as java Object 在Spark Java中使用pac4j安全过滤器时,如何获取发布请求的参数? - How do I get the parameters of a post request when using a pac4j security filter in Spark Java? 如何在Filter中获取请求 - How can i get request in Filter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM