title: How to execute blocking calls within a Spring Webflux / Reactor Netty web application
body: <p>In my use case where I have a Spring Webflux microservice with Reactor Netty, I have the following dependencies:</p>
  
  <ul>
  <li><code>org.springframework.boot.spring-boot-starter-webflux</code> (2.0.1.RELEASE)</li>
  <li><code>org.springframework.boot.spring-boot-starter-data-mongodb-reactive</code> (2.0.1.RELEASE)</li>
  <li><code>org.projectreactor.reactor-spring</code> (1.0.1.RELEASE)</li>
  </ul>
  
  <p>For a very specific case I need to retrieve some information from my Mongo database, and process this into query parameters send with my reactive <code>WebClient</code>. As the <code>WebClient</code> nor the <code>UriComponentsBuilder</code> accepts a Publisher (Mono / Flux) I used a <code>#block()</code> call to receive the results. </p>
  
  <p>Since <code>reactor-core</code> (version 0.7.6.RELEASE) which has been included in the latest <code>spring-boot-dependencies</code> (version 2.0.1.RELEASE) it is not possible anymore to use: <code>block()/blockFirst()/blockLast() are blocking, which is not supported in thread xxx</code>, see -> <a href="https://github.com/reactor/reactor-netty/issues/312" rel="nofollow noreferrer">https://github.com/reactor/reactor-netty/issues/312</a></p>
  
  <p>My code snippet:</p>
  
  <pre class="lang-java prettyprint-override"><code>public Mono&lt;FooBar&gt; getFooBar(Foo foo) {
      MultiValueMap&lt;String, String&gt; parameters = new LinkedMultiValueMap&lt;&gt;();
      parameters.add("size", foo.getSize());
      parameters.addAll("bars", barReactiveCrudRepository.findAllByIdentifierIn(foo.getBarIdentifiers()) // This obviously returns a Flux
          .map(Bar::toString)
          .collectList()
          .block());
  
      String url = UriComponentsBuilder.fromHttpUrl("https://base-url/")
          .port(8081)
          .path("/foo-bar")
          .queryParams(parameters)
          .build()
          .toString();
  
      return webClient.get()
          .uri(url)
          .retrieve()
          .bodyToMono(FooBar.class);
  }
  </code></pre>
  
  <p>This worked with <code>spring-boot</code> version 2.0.0.RELEASE, but since the upgrade to version 2.0.1.RELEASE and hence the upgrade from <code>reactor-core</code> to version 0.7.6.RELEASE it is not allowed anymore.</p>
  
  <p>The only real solution I see is to include a block (non-reactive) repository / mongo client as well, but I'm not sure if that is encouraged. Any suggestions?  </p>