小编jon*_*nas的帖子

在Finagle中记录远程主机

我想在使用Finagle Client时将被叫远程主机记录到STDOUT.但据我所知,这是不可能的com.twitter.finagle.http.filter.LoggingFilter; 其#format(示例见下文)方法无法访问实际主机:

  • request.remoteHost() 回报 0.0.0.0
  • request.remoteAddress() 返回一个基本上包含上述IP的对象
  • request.host()返回一个None对象

我的第一个猜测是,访问主机是不可能的,因为Finagle的客户端负载平衡在堆栈中发生得更深.

这是我使用的测试代码:

    LoggingFilter<Request> loggingFilter = new LoggingFilter<>(
            new Logger(this.getClass().getSimpleName(), java.util.logging.Logger.getLogger(this.getClass().getSimpleName())),

            new LogFormatter<Request, Response>() {
                @Override
                public String format(Request request, Response reply, Duration replyTime) {
                    return null;
                }

                @Override
                public String formatException(Request request, Throwable throwable, Duration replyTime) {
                    return null;
                }
            });

    Service<Request, Response> service = Http.client().newService("localhost:8090,localhost:8091");
    Future<Response> response = loggingFilter.andThen(service).apply(Request.apply("/profiles/me"));
Run Code Online (Sandbox Code Playgroud)

finagle twitter-finagle

3
推荐指数
1
解决办法
418
查看次数

标签 统计

finagle ×1

twitter-finagle ×1