Issue
Following Configure the Web Server , I add a NettyWebServerFactoryCustomizer
@Configuration
public class NettyWebServerFactoryCustomizer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
@Override
public void customize(NettyReactiveWebServerFactory factory) {
factory.addServerCustomizers(httpServer -> {
return httpServer
.wiretap(true)
.metrics(true, s->s)
.doOnConnection(conn -> {
conn.addHandlerFirst(new ReadTimeoutHandler(50, TimeUnit.MILLISECONDS));
});
});
}
}
I have two questions:
When I run the app, the
customize
function is not hit. Where do I miss? My purpose is to enable the Netty metrics, I can't find any documents about config the metrics in theapplication.yml
file. so I add theNettyWebServerFactoryCustomizer
.The second parameter of
.metrics(true, s->s)
is auriTagValue
, Are there any example about how to pass in value? I just uses->s
because I refer this, but this maybe can't avoid cardinality explosion, Are there any function likeServerWebExchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)
simple give us the templated URL?
Solution
I found the workaround of the question 1: define a bean instead of implementing WebServerFactoryCustomizer
@Bean
public ReactiveWebServerFactory reactiveWebServerFactory() {
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
factory.addServerCustomizers(builder -> builder
.wiretap(true)
.metrics(true,s->s)
.accessLog(true)
.doOnConnection(conn -> {
conn.addHandlerFirst(new ReadTimeoutHandler(50, TimeUnit.MILLISECONDS));
}));
return factory;
}
Answered By - gfan
Answer Checked By - Mildred Charles (JavaFixing Admin)