1
我想在使用Finagle客戶端時將被叫遠程主機記錄到STDOUT。但據我所知,這是不可能通過com.twitter.finagle.http.filter.LoggingFilter
;其#format
(例如見下文)方法無法訪問實際的主機:在Finagle中記錄遠程主機
request.remoteHost()
返回0.0.0.0
request.remoteAddress()
返回其基本上含有上述IPrequest.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"));