Trying to push message to upstream whenever they are available/ready and close connection after flush, rather than polling for message using spring reactive flux interval.
@GetMapping(value = "/getValue/{randomId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> statusCheck(@PathVariable("randomId") @NonNull String randomId) {
return Flux.<String>interval(Duration.ofSeconds(3))
.map(status -> {
if (getSomething(randomId).
equalsIgnoreCase("value"))
return "value";
return "ping";
}).take(Duration.ofSeconds(60)).timeout(Duration.ofSeconds(60));
}
Kafka listener updates randomId value in a map as it gets, getSomething method checks for randomId value in intervals in map. So instead of checking in intervals and storing data in map, i want to push message to client when listener receives.