title: How to limit the request/second with WebClient?
body: <p>I'm using a <code>WebClient</code> object to send Http Post request to a server.
  It's sending a huge amount of requests quite rapidly (there is about 4000 messages in a <code>QueueChannel</code>). The problem is... it seems the server can't respond fast enough... so I'm getting a lot of server error 500 and connexion closed prematurely.</p>
  
  <p>Is there a way to limit the number of request per seconds ? Or limit the number of threads it's using ?</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>The Message endpoint processe message in a QueueChannel :</p>
  
  <pre><code>@MessageEndpoint
  public class CustomServiceActivator {
  
      private static final Logger logger = LogManager.getLogger();
  
      @Autowired
      IHttpService httpService;
  
      @ServiceActivator(
              inputChannel = "outputFilterChannel",
              outputChannel = "outputHttpServiceChannel",
              poller = @Poller( fixedDelay = "1000" )
      )
      public void processMessage(Data data) {
          httpService.push(data);
          try {
              Thread.sleep(20);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>The WebClient service class :</p>
  
  <pre><code>@Service
  public class HttpService implements IHttpService {
  
      private static final String URL = "http://www.blabla.com/log";
  
      private static final Logger logger = LogManager.getLogger();
  
      @Autowired
      WebClient webClient;
  
      @Override
      public void push(Data data) {
          String body = constructString(data);
          Mono&lt;ResponseEntity&lt;Response&gt;&gt; res = webClient.post()
                  .uri(URL + getLogType(data))
                  .contentLength(body.length())
                  .contentType(MediaType.APPLICATION_JSON)
                  .syncBody(body)
                  .exchange()
                  .flatMap(response -&gt; response.toEntity(Response.class));
  
          res.subscribe(new Consumer&lt;ResponseEntity&lt;Response&gt;&gt;() { ... });
      }
  }
  </code></pre>