title: Avoid GC pressure with Reactor Publisher
body: <p>I search for a way to correctly employ Publishers from Project Reactor without producing useless GC pressure by instantiating the whole pipeline on each call.</p>
  
  <p>In our code a typical handle function answering inter service HTTP requests looks like so:</p>
  
  <pre><code>final List&lt;Function&lt;ChangeEvent, Mono&lt;Void&gt;&gt;&gt; triggerOtherMicroservices;
  
  @PostMapping("/handle")
  public Mono&lt;Void&gt; handle(@RequestBody ChangeEvent changeEvent) {
      return Mono
              .defer(() -&gt; someService.callToAnotherMicroServiceToFetchData(changeEvent))
              .subscribeOn(Schedulers.parallel())
              .map(this::mapping)
              .flatMap(data -&gt; databaseService.save(data))
              .thenMany(Flux.fromIterable(triggerOtherMicroservices).flatMap(t -&gt; t.apply(changeEvent)))
              .then();
  }
  </code></pre>
  
  <p>If I understand correctly this means, on each invocation of <code>handle</code> the whole pipeline (which normally has huge stacktraces) needs to be instantiated (and thus collected later). </p>
  
  <p>My question is: Can I somehow "prepare" the whole flow once and reuse it later? </p>
  
  <p>I was thinking about something like <code>Mono.create( ... ) ....</code>. Or, am I completely wrong and there is no need to think about optimization here?</p>
  
  <p>EDIT: </p>
  
  <p>Thinking further I could do:</p>
  
  <pre><code>final List&lt;Function&lt;ChangeEvent, Mono&lt;Void&gt;&gt;&gt; triggerOtherMicroservices;
  
  final Mono&lt;Void&gt; mono = Mono
          .defer(() -&gt; Mono
                  .subscriberContext()
                  .map(context -&gt; context.get("event"))
                  .flatMap(event -&gt; someService.callToAnotherMicroServiceToFetchData(event))
          )
          .subscribeOn(Schedulers.parallel())
          .flatMap(data -&gt; databaseService.save(data))
          .thenMany(Mono
                  .subscriberContext()
                  .map(context -&gt; context.get("event"))
                  .flatMap(event -&gt; Flux
                          .fromIterable(triggerOtherMicroservices)
                          .flatMap(t -&gt; t.apply(event)))
          )
          .then(); 
  
  public Mono&lt;Void&gt; handle(@Validated ChangeEvent changeEvent) throws NoSuchElementException {
      return mono.subscriberContext(context -&gt; context.put("event", changeEvent));
  }
  </code></pre>
  
  <p>Anyway, I doubt this is what <code>subscriberContext</code> is meant for.</p>