Rule Request: AvoidReactorOnEachOperator
Closed this issue · 0 comments
jborgers commented
Using Reactor Hooks.onEachOperator means executing the code on every operator in the Reactor flow, for every element. This typically means much processing time.
The recommendation is to just do processing when actually needed.
example:
@Configuration
public class MdcContextLifterConfiguration {
private String MDC_CONTEXT_REACTOR_KEY = MdcContextLifterConfiguration.class.getName();
@PostConstruct
private void contextOperatorHook() {
Hooks.onEachOperator(MDC_CONTEXT_REACTOR_KEY,
Operators.lift((scannable, coreSubscriber) -> new MdcContextLifter<>(coreSubscriber))
);
}
@PreDestroy
private void cleanupHook() {
Hooks.resetOnEachOperator(MDC_CONTEXT_REACTOR_KEY);
}
}