Add a heartbeat executor for SSE emitters#34878
Add a heartbeat executor for SSE emitters#34878reda-alaoui wants to merge 3 commits intospring-projects:mainfrom
Conversation
Signed-off-by: Réda Housni Alaoui <reda-alaoui@hey.com>
There was a problem hiding this comment.
Thanks for putting together a pull request. Some comments below.
I don't think there needs to be a public SseEmitterHeartbeatExecutor contract and implementation. This could be simply a TaskScheduler with the rest managed internally in a dedicated package private class (similar to ReactiveTypeHandler).
Heartbeats should not be emitted if emitters are already busy sending. Perhaps each emitter can keep a timestamp of the last send, and expose a method to send a heartbeat that would send only if a certain amount of time has passed since the last send.
Controllers that use Flux for SSE can easily incorporate heartbeats. Such Flux return values are also turned into SseEmitters, and so adding heartbeats to every emitter you could end up with duplicate heartbeat streams for the same emitter. It makes me think that emitters should actually opt into heartbeats, and then they should be called to send a heartbeat only if they opted in.
If I understand correctly, you'd like each instance of |
|
Good question. We could make it opt-in by default so for On that note, I should also add that this would be expected to be configurable through the WebMvc config. I think |
|
@rstoyanchev could you take a look at the new changes? Here are some things I had doubts about while writing the implementation. Now that
I think there should be more tests to write but I prefer to do that once you tell me I am heading the right way. |
Signed-off-by: Réda Housni Alaoui <reda-alaoui@hey.com>
|
Gentle ping 😇 |
Fix #33355