Created
November 22, 2020 22:16
-
-
Save razorcd/0d8ad4bf60f83e898f8b4bd84d084dc2 to your computer and use it in GitHub Desktop.
Scaling reactive APIs - www.razorcodes.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final Map<String,EventStream> streamsList = new ConcurrentHashMap<>(); | |
public Flux<CustomerUpdatedEvent> getStreamEvents(String eventStreamId, long fromMs) { | |
//add new eventStream to Set | |
EventStream eventStream = new EventStream(eventStreamId, fromMs, 0, new HashSet()); | |
streamsList.putIfAbsent(eventStreamId, eventStream); | |
//create a Flux and add the Sink to the EventStream to be used for publishing | |
Flux<Object> events = Flux.create(sink -> eventStream.addStream(sink)); | |
//configure the Flux and return it | |
return events | |
.cast(CustomerUpdatedEvent.class) | |
.timeout(Duration.ofMinutes(60)) | |
.doFinally(e -> { | |
eventStream.removeStream(eventStream); | |
log.debug("Finally UNRegistering consumer:{}. Cause:{}.", eventStreamId, e); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment