【问题标题】:Java spring integration gateway request response time loggingJava spring 集成网关请求响应时间日志记录
【发布时间】:2020-07-10 22:42:18
【问题描述】:

我正在使用 spring 集成网关来公开休息服务。它配置了请求通道和回复通道。我正在寻找能够给我每次休息操作所需时间的配置。

以下是网关配置:

<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。正在为网关寻找类似的东西?

【问题讨论】:

  • 也许你可以检查一下:stackoverflow.com/questions/32213467/…
  • 你目前的配置是什么?
  • @Artem,这是我当前的网关配置。
  • 请不要在 cmets 中放置错误代码 sn-ps。最好用适当的格式编辑您的问题。
  • 看看我是如何格式化您的问题以使其他人可读的。请学习如何在 SO 上发帖:stackoverflow.com/help/how-to-ask

标签: java spring spring-integration


【解决方案1】:

既然您谈到了 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 的拦截器中注入startTime 标头,并在tranResponseChan 的拦截器中进行计算。

另一种方法是依靠通道上的 Micrometer metrix 或 MessageHandlers: https://docs.spring.io/spring-integration/docs/current/reference/html/system-management.html#mgmt-channel-features

【讨论】:

  • 感谢 Artem,注入标头的第二个选项对我来说看起来不错。第三个选项需要 jmx 访问权限。感谢您的解决方案。
  • 是的,我知道第三个选项有点涉及,但即使使用第二个选项,如果您需要做更多的事情而不只是记录,您也需要确定如何访问该计算的时间段.
  • 如果你的回答没问题,那么让我们考虑一下:stackoverflow.com/help/someone-answers
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-23
相关资源
最近更新 更多