【发布时间】:2021-07-21 19:46:45
【问题描述】:
我正在尝试根据进行 WebClient 调用时收到的请求和响应数据来创建 POJO。但我没有以字符串/JSON 可读形式获取请求正文,而是获取了 BodyInsertor。我正在使用 Exchange 过滤器。
public ExchangeFilterFunction logWebRequest() {
return (request, next) -> {
log.info("Entered in logWebRequest for WebClient");
long startTime = System.currentTimeMillis();
Mono<ClientResponse> response = next.exchange(request);
long processingTimeInMs = System.currentTimeMillis() - startTime;
// request.body() -> Gives Body Insertor
WebRequestLog webRequestLog = webRequestService.makeWebRequestLog(request, response.block());
webRequestLog.setProcessingTimeInMs(processingTimeInMs);
log.info("WebRequest to be produced to kafka topic: " + webRequestLog);
kafkaService.produceAuditLog(webRequestLog);
return response;
};
}
我关注了一些文章,例如 https://andrew-flower.com/blog/webclient-body-logging 和 https://www.gitmemory.com/issue/spring-projects/spring-framework/24262/570245788,但对我没有任何帮助。
我的最终目标是用他们的身体捕获请求和响应,并生成为 Kafka 收集的数据。
【问题讨论】:
-
您的问题与 Spring Kafka 完全无关。请在为您的问题选择标签时小心。
标签: java spring spring-boot logging