title: Spring boot SSE (Server sent events): how to send response dynamically
body: <p>I am new to SSE (Server Sent Events) . I found a way to send response using SSE in spring boot. I am able to send response for every 20 seconds. I used below code for the same. </p>
  
  <pre><code>public Flux&lt;UserDto&gt; fetchUserEvent() {
          return Flux.interval(Duration.ofSeconds(20)).map(intr -&gt; generateUserEvent()).flatMapIterable(x -&gt; x);
      }
  
  generateUserEvent() - verify if new user added in DB. If it found user data, will return the same or will return empty object (new UserDto())
  </code></pre>
  
  <p>But the problem is , this method being called for every 20 seconds . </p>
  
  <p>But , My requirement is to send the empty response to client every 20 seconds and send the respone whenever new user added to DB. </p>
  
  <p>How can I achieve my goal? Or I am totally wrong conceptually.</p>