【问题标题】:WebClient logging without deprecated method tcpClient.bootstrap()不推荐使用方法 tcpClient.bootstrap() 的 WebClient 日志记录
【发布时间】:2021-02-16 01:42:11
【问题描述】:

我正在尝试在我的中间件应用程序中进行一些日志记录,我想在其中记录后端系统的请求和响应。我想用Netty(因为我们实现了困难的SslContext)。

我正在尝试通过本教程来学习它:https://www.baeldung.com/spring-log-webclient-calls(第 4.2 章。使用 Netty HttpClient 进行日志记录)。

为了更好看的日志,有部分代码:

HttpClient httpClient = HttpClient
  .create()
  .tcpConfiguration(
    tc -> tc.bootstrap(
      b -> BootstrapHandlers.updateLogSupport(b, new CustomLogger(HttpClient.class))))
  .build()

bootstrap(...) 方法已被弃用。我可以用什么代替?

【问题讨论】:

标签: java reactor-netty


【解决方案1】:

如果您需要CustomLogger 来请求/响应(根据上面的评论),那么您可以执行以下操作:

CustomLogger customLogger = new CustomLogger(HttpClient.class);         
HttpClient httpClient = HttpClient
                .create()
                .doOnRequest((request, connection) -> {
                    connection.addHandlerFirst(customLogger);
                });

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    相关资源
    最近更新 更多