我尝试将SSE端点添加到我的应用程序,以将对象的更新通知客户端。方法“ getPlayerStatus(playerId)”正在使用JPA存储库读取数据库中的数据。我已经用@Transactional注释了此方法,但问题仍然相同。有什么想法吗?
@GetMapping(value = "/status-sse/{playerId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> getPlayerStatusSse(@PathVariable String playerId) {
return Flux.interval(Duration.ofSeconds(1)).map(sequence -> {
try {
LOGGER.info("Getting playerstatus {}", getPlayerStatus(playerId));
return getPlayerStatus(playerId);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return "";
}
});
}```