title: Server Sent Event Spring Webflux return event name in response from rest controller
body: <p>I am using SSE with reactor Flux for capturing linux system metrics and publishing to browser(javascript eventsource).</p>
  
  <p>Currently, the problem is not able to send specific data to specific client. After going through multiple SO posts, it is told to use event listener in the eventsource and response from server should have <strong>event</strong> as key in the response. </p>
  
  <p>Since, I am returning an object from the server, is it enough to have <strong>event</strong> as one of the key in the response json which will be identified by the eventsource.</p>
  
  <p>Setting an unique number in the client side, which will be return in the <strong>event</strong> key in the json response.</p>
  
  <p>Thanks for the help !</p>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code>jsonStreamObjectHeap.addEventListener("197e08e-f9a4-4e6e-9a04-220ade08a8f4",function(e){
          $.each(message, function(index, value) {
             /*some operation*/
          });
          }
  </code></pre>
  
  <p><strong>Response From Rest Controller:</strong></p>
  
  <pre><code>{
     "event":"197e08e-f9a4-4e6e-9a04-220ade08a8f4",
     "data":"2048"
  }
  </code></pre>
  
  <p><strong>Rest Controller Code:</strong></p>
  
  <pre><code> Flux&lt;Long&gt; interval = Flux.interval(Duration.ofSeconds(1));
          interval.subscribe((i) -&gt; testStreamList.forEach(testStream -&gt; {
              try {
                  generateTestStream(testStream, UUID);
              } catch (JsonProcessingException e) {
                  e.printStackTrace();
              }
          }));
   Flux&lt;List&lt;TestStream&gt;&gt; transactionFlux = Flux.fromStream(Stream.generate(() -&gt; testStreamList));
   return Flux.zip(interval, transactionFlux).map(Tuple2::getT2);
  </code></pre>