title: Spring WebFlux SSE + angular - detect open connection
body: <p>I created a Server-Sent Event connection with Spring and Angular to send a periodic message about possible incoming restart.</p>
  <p>But the SSE connection is limited to 6 connections per user. This means that if I open more than 6 tabs, everything slows down because the browser can't get connections - the page doesn't load.</p>
  <p>angular</p>
  <pre><code>const source = new EventSource('/api/incoming-restart-event')
  source.addEventListener('message', (message: MessageEvent) =&gt; {
    minutesUntilRestart = message.data
  })
  </code></pre>
  <p>Spring</p>
  <pre><code>@GetMapping(path = &quot;/incoming-restart-event&quot;, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  public Flux&lt;Date&gt; incomingRestartEventStream() {
      return Flux.interval(Duration.ofSeconds(3), Duration.ofSeconds(100))
              .map(sequence -&gt; incomingRestartService.getIncomingRestartTime() != null
                      ? incomingRestartService.getIncomingRestartTime()
                      : new Date(0));
  }
  </code></pre>
  <p>What would be the best way to only send updates to the active tab (or just last active tab)? Basically - I want to make sure that we aren't opening 6+ open connections.</p>
  <p>I would prefer to handle this in the back-end so I don't have to build some kind of a front-end session handler for trying to count user's active tabs.</p>