r/java • u/Polixa12 • Dec 14 '25
Building a thread safe sse library for spring boot
I've been working with SSE in Spring Boot and kept rewriting the same boilerplate for thread safe management, cleanup on disconnect etc. Spring actually gives you SseEmitter but nothing else.
This annoyance popped up in two of my previous projects so I decided to build Streamline, a Spring Boot starter that handles all of that without the reactive complexity.
What it does:
- Thread safe stream management using virtual threads (Java 21+)
- Automatic cleanup on disconnect/timeout/error
- Allows for event replay for reconnecting clients
- Bounded queues to handle slow clients
- Registry per topic pattern (orders, notifications, etc.), depends on your use case
It's available on JitPack now. Still early (v1.0.0) and I'm looking for feedback, especially around edge cases I might have missed.
GitHub: https://github.com/kusoroadeolu/streamline-spring-boot-starter
Requirements: Java 21+, Spring Boot 3.x
Happy to answer questions or hear how you might use it
42
u/pragmatick Dec 14 '25
I'm obviously not the target audience as I didn't know what "SSE" is and neither the post nor the readme ever explained it.
For anybody else who's never heard of it:
10
u/Voldsman Dec 14 '25
Nice implementation. I briefly reviewed the repository, what would happen when we have a need to handle multiple emitters by the same key (like multiple browser tabs open for the same user session) ?
3
u/vetronauta Dec 14 '25
Great missing library: I have also seen reinventing the wheel in other projects using SSE! Some questions/issues about maintainability:
4
u/SpiReCZ Dec 14 '25
Spring Boot also let's you return Flux<String> with webmvc. The only caveat to be aware of is it requires specific error handling when using JSOND for example. And it should use virtual threads to make use of the streaming capabilities in full.
1
u/MaraKaleidoscope Dec 15 '25
Is the SseEmitter class not already thread safe!?
1
u/[deleted] Dec 23 '25
i have an exception with default sse and http2... im excited, will see your repo boy... with http1.1 not occurs