我正在使用 spring 集成网关来公开休息服务。它配置了请求 channel 和回复 channel 。我正在寻找能够为我提供每次休息操作所需时间的配置。
下面是网关配置:
<int:gateway id="testServiceGateway"
service-interface="com.test.ws.TransactionServices"
default-reply-time-out="5000"
error-channel="txErrorChan">
<int:method name="evaluateTransaction"
request-channel="tranRequestChan"
reply-channel="tranResponseChan"
reply-time-out="3000" />
</int:gateway>
例如:我为 kafka-outbound-channel-adapter 使用了自定义 request-handler-advice-chain。正在寻找类似的网关吗?
最佳答案
既然您谈论了 REST 调用,您可能可以考虑使用跟踪工具,例如 Spring Cloud Sleuth:https://cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/2.2.2.RELEASE/reference/html/#http-client-integration
尽管对于如此简单的用例,我只会在调用 TransactionServices.evaluateTransaction()
方法之前和之后获取当前时间来计算整个调用周期。
您还可以按照我在提到的答案中的建议 Spring Integration - Log time taken for whole file processing 。因此,您可以在 tranRequestChan
的拦截器中注入(inject) startTime
header ,并在 tranResponseChan
的拦截器中进行计算。
另一种方法是依赖 channel 或 MessageHandler
上的 Micrometer 度量:https://docs.spring.io/spring-integration/docs/current/reference/html/system-management.html#mgmt-channel-features
关于Java spring集成网关请求响应时间记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60932653/