查看Spring Actuator MetricsWebFilter
并看到了这段代码:
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange).compose((call) -> filter(exchange, call));
}
private Publisher<Void> filter(ServerWebExchange exchange, Mono<Void> call) {
long start = System.nanoTime();
ServerHttpResponse response = exchange.getResponse();
return call.doOnSuccess((done) -> success(exchange, start))
... more code ...
}
没有compose()映射会有什么区别吗?
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange).doOnSuccess( ... ) ... more code...
}
我的线索是,compose()与transform(). doOnSuccess()但是每个订阅者也执行一次。
是否只是为了方便,使用filter(...)函数而不是内联代码?
动漫人物
相关分类