Java spring集成网关请求响应时间记录

标签 java spring spring-integration

我正在使用 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/

相关文章:

java - 更新 Wicket WebMarkupContainer

java - 无法为当前线程获取事务同步 session

java - wget 文件下载 ftp waitfor() 挂起

java - 注销后, session 没有结束

java - Spring 启动 2 Oauth2

java - 在当前项目和插件组 org.codehaus.mojo 中找不到前缀为 'exec' 的插件

java - 如何注册 org.springframework.integration.monitor.IntegrationMBeanExporter

java - 用于多个 JSON 对象模式的 Spring IntegrationFlow

java - Spring Integration Java DSL 单元测试 - 如何模拟服务激活器类或其他组件/端点?

java - Spring Batch - 自定义项目编写器未写入文件