Spring integration Spring集成&x2B;记录http适配器(或任何端点)的响应时间
作为非功能性需求的一部分,我必须在spring集成流中记录每个http出站调用的响应时间 我有一系列http:outbound网关,它们进行RESTAPI调用(JSON中的请求/响应)。我必须记录不同的内容,如请求负载、服务端点名称、状态(成功/失败) 我尝试使用ChannelInterceptorAdapter,如:Spring integration Spring集成&x2B;记录http适配器(或任何端点)的响应时间,spring-integration,Spring Integration,作为非功能性需求的一部分,我必须在spring集成流中记录每个http出站调用的响应时间 我有一系列http:outbound网关,它们进行RESTAPI调用(JSON中的请求/响应)。我必须记录不同的内容,如请求负载、服务端点名称、状态(成功/失败) 我尝试使用ChannelInterceptorAdapter,如: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.integ
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
import org.springframework.stereotype.Component;
@Component(value = "integrationLoggingInterceptor")
public class IntegrationLoggingInterceptor extends ChannelInterceptorAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(IntegrationLoggingInterceptor.class);
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
LOGGER.debug("Post Send - Channel " + channel.getClass());
LOGGER.debug("Post Send - Headers: " + message.getHeaders() + " Payload: " + message.getPayload() + " Message sent?: " + sent);
}
@Override
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
try {
LOGGER.debug("Post Receive - Channel " + channel.getClass());
LOGGER.debug("Post Receive - Headers: " + message.getHeaders() + " Payload: " + message.getPayload());
} catch(Exception ex) {
LOGGER.error("Error in post receive : ", ex);
}
return message;
}
}
import org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入org.springframework.integration.Message;
导入org.springframework.integration.MessageChannel;
导入org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
导入org.springframework.stereotype.Component;
@组件(value=“integrationLoggingInterceptor”)
公共类集成LoggingInterceptor扩展ChannelInterceptorAdapter{
私有静态最终记录器Logger=LoggerFactory.getLogger(IntegrationLoggingInterceptor.class);
@凌驾
public void postSend(消息消息、消息通道、布尔发送){
debug(“Post Send-Channel”+Channel.getClass());
LOGGER.debug(“发送后-标题:“+message.getHeaders()+”有效负载:“+message.getPayload()+”已发送消息?:“+sent”);
}
@凌驾
公共消息postReceive(消息消息、消息通道){
试一试{
debug(“Post Receive-Channel”+Channel.getClass());
debug(“Post-Receive-Headers:+message.getHeaders()+”负载:+message.getPayload());
}捕获(例外情况除外){
LOGGER.error(“接收后出错:”,ex);
}
返回消息;
}
}
但我不知道如何获取每个http:outbound网关的响应时间
任何提示/建议/提示/建议都将不胜感激。好的,您应该编写
拦截器
,但不适用于频道
和
。有一个特点
它可以是AOPAdvice
的任何实现。出于您的目的,MethodInterceptor
是一个不错的选择。该建议适用于AbstractReplyProducingMessageHandler.HandlerRequestMessage
,在这里完成了真正的“艰苦”工作 我用它工作: