title: Spring Webflux: Extract value from Mono
body: <p>I am new to spring webflux and am trying to perform some arithmetic on the values of two monos. I have a product service that retrieves account information by calling an account service via webClient. I want to determine if the current balance of the account is greater than or equal to the price of the product.</p>
  
  <pre><code>Mono&lt;Account&gt; account = webClientBuilder.build().get().uri("http://account-service/user/accounts/{userId}/",userId)
  .retrieve().bodyToMono(Account.class);
  
  
  //productId is a path variable on method
  Mono&lt;Product&gt; product =this.productService.findById(productId);
  
  </code></pre>
  
  <p>When I try to block the stream I get an error</p>
  
  <blockquote>
    <p>block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2</p>
  </blockquote>
  
  <pre><code>//Causes Error
  Double accountBalance = account.map(a-&gt;a.getBalance()).block():
  
  Double productPrice = product.map(p-&gt;p.getPrice()).block();
  
  ///Find difference, send response accordingly....
  
  </code></pre>
  
  <p>Is this the correct approach of there is another, better way to achieve this? I was also thinking something along the lines of:</p>
  
  <pre><code>Mono&lt;Double&gt; accountBalance = account.map(a-&gt;a.getBalance()):
  
  Mono&lt;Double&gt; productPrice = product.map(p-&gt;p.getPrice());
  
  Mono&lt;Double&gt; res = accountBalance.zipWith(productPrice,(b,p)-&gt; b-p);
  
  //Something after this.....
  
  </code></pre>