title: Mutiny - How to group items to send request by blocks
body: <p>I'm using Mutiny extension (for Quarkus) and I don't know how to manage this problem.</p>
  <p>I want to send many request in an async way so I've read about Mutiny extension. But the server closes the connection because it receives thousand of them.</p>
  <p>So I need:</p>
  <ul>
  <li>Send the request by blocks</li>
  <li>After all request are sent, do things.</li>
  </ul>
  <p>I've been using Uni object to combine all the responses as this:</p>
  <pre><code>Uni&lt;Map&lt;Integer, String&gt;&gt; uniAll = Uni.combine()
     .all()
     .unis(list)
     .combinedWith(...);
  </code></pre>
  <p>And then:</p>
  <pre><code>uniAll.subscribe()
        .with(...);
  </code></pre>
  <p>This code, send all the request in paralell so the server closes the connection.</p>
  <p>I'm using group of Multi objects, but I don't know how to use it (in Mutiny docs I can't found any example).</p>
  <p>This is the way I'm doing now:</p>
  <pre><code>          //Launch 1000 request
            for (int i=0;i&lt;1000;i++) {
              multi = client.getAbs(&quot;https://api.*********.io/jokes/random&quot;)
                        .as(BodyCodec.jsonObject())
                        .send()
                        .onItem().transformToMulti(
                                array -&gt; Multi.createFrom()
                                         .item(array.body().getString(&quot;value&quot;)))
                                         .group()
                                         .intoLists()
                                         .of(100)
                                         .subscribe()
                                         .with(a-&gt;{
                                           System.out.println(&quot;Value: &quot;+a);
                                          });
            }
  
  </code></pre>
  <p>I think that the subscription doesn't execute until there are &quot;100&quot; groups of items, but I guess this is not the way because it doesn't work.</p>
  <p>Does anybody know how to launch 1000 of async requests in blocks of 100?</p>
  <p>Thanks in advance.</p>
  <p><strong>UPDATED 2021-04-19</strong></p>
  <p>I've tried with this approach:</p>
  <pre><code>    List&lt;Uni&lt;String&gt;&gt; listOfUnis = new ArrayList&lt;&gt;();
      for (int i=0;i&lt;1000;i++) {
          listOfUnis.add(client
                         .getAbs(&quot;https://api.*******.io/jokes/random&quot;)
                         .as(BodyCodec.jsonObject())
                         .send()
                         .onItem()
                         .transform(item -&gt; item
                                          .body()
                                          .getString(&quot;value&quot;)));
        }
  
  
      Multi&lt;Uni&lt;String&gt;&gt; multiFormUnis = Multi.createFrom()
                                              .iterable(listOfUnis);
  
      List&lt;String&gt; listOfResponses = new ArrayList&lt;&gt;();
  
      List&lt;String&gt; listOfValues = multiFormUnis.group()
                   .intoLists()
                   .of(100)
                   .onItem()
                   .transformToMultiAndConcatenate(listOfOneHundred -&gt; 
                   {
                       System.out.println(&quot;Size: &quot;+listOfOneHundred.size());
                       
                       for (int index=0;index&lt;listOfOneHundred.size();index++) {
                           listOfResponses.add(listOfOneHundred.get(index)
                                                               .await()
                                                               .indefinitely());                          
                       }                       
                  
                  return Multi.createFrom()
                              .iterable(listOfResponses);
                   })
                   .collectItems()
                   .asList()
                   .await()
                   .indefinitely();
  
      for (String value : listOfValues) {
          System.out.println(value);
      }
  
  </code></pre>
  <p>When I put this line:</p>
  <pre><code> listOfResponses.add(listOfOneHundred.get(index)
                                       .await()
                                       .indefinitely()); 
  </code></pre>
  <p>The responses are printed one after each other, and when the first 100s group of items ends, it prints the next group. The problem? There are sequential requests and it takes <strong>so much time</strong></p>
  <p>I think I am close to the solution, but I need to know, how to send the parallel request only in group of 100s, because if I put:</p>
  <pre><code>subscribe().with()
  </code></pre>
  <p>All the request are sent in parallel (and not in group of 100s)</p>