title: Serving different webflux endpoints on different eventloops
body: <p>I have ported a large spring-web codebase to spring-webflux. There two sets of endpoints, some critical endpoints that must be fast, and some others that are not vital if they end up blocking in production. I can validate that none of the critical endpoints block on the eventloop thread, but validating all the other endpoints is not feasible. I would like to run them on a different threadpool or eventloop, so if they block, they do not affect the critical endpoints.</p>
  
  <p>How would I go about this?</p>
  
  <p>I've tried using reflection to find all the handlers that either should or shouldn't be on a secondary eventloop, but can't think of a way to assign them to it. Alternatively, is it possible to run both spring-web and spring-webflux, and have spring-web serve the non-critical endpoints?</p>
  
  <p>I've managed to get the handlers from the handler registry like so:</p>
  
  <pre><code>@Component
  class HandlerFinder(val requestMappingHandlerMappings: List&lt;RequestMappingHandlerMapping&gt;) {
  
      @PostConstruct
      fun start() {
          for (rmhm : RequestMappingHandlerMapping in requestMappingHandlerMappings) {
              val handlerMethods: Map&lt;RequestMappingInfo, HandlerMethod&gt; = rmhm.handlerMethods
  
              for ((mapping, method) in handlerMethods) {
                  for (urlPattern in mapping.patternsCondition.patterns) {
                      log.info("${method.beanType.name}#${method.method.name} &lt;-- ${urlPattern}")
                  }
              }
          }
      }
  
      companion object {
          private val log = LoggerFactory.getLogger(HandlerFinder::class.java)
      }
  }
  </code></pre>
  
  <p>I think the next step would be to somehow change the handlers to be wrapped in something like below, but I'm not sure how to change this in the handler registry:</p>
  
  <pre class="lang-java prettyprint-override"><code>Mono.fromCallable(() -&gt; { ... handler method goes here ...}).publishOn(Schedulers.elastic());
  </code></pre>
  
  <p>I know I can unregister the mapping with <code>rmhm.ungreisterMapping(mapping)</code> and then re-register it with something like <code>rmhm.registerMapping(mapping, method.bean, method.method)</code>, but I'll need to create new methods to wrap the existing ones somehow.</p>