Created
August 21, 2019 00:30
-
-
Save timjonesdev/60a2660ee9863052afbad3e0e7111860 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Subscribe to watch updates to a particular team | |
* | |
* @param request - must be of the form /{name} | |
* @return a subscription to a Server Sent Event which | |
* fires every time the requested team is updated in the fantasy_db.teams collection. | |
* The subscription is watching a change stream in MongoDB | |
*/ | |
public Mono<ServerResponse> watchTeam(ServerRequest request) { | |
String teamName = request.pathVariable("name"); | |
Flux<ServerSentEvent<Team>> sse = this.teamWatcher.watchForTeamChanges(teamName) | |
.map(team -> ServerSentEvent.<Team>builder() | |
.data(team) | |
.build()); | |
return ServerResponse.ok().body(BodyInserters.fromServerSentEvents(sse)); | |
} | |
/** | |
* Subscribe to watch changes for any team in the collection | |
* | |
* @param request | |
* @return | |
*/ | |
public Mono<ServerResponse> watchTeams(ServerRequest request) { | |
Flux<ServerSentEvent<Team>> sse = this.teamWatcher.watchForTeamCollectionChanges() | |
.map(team -> ServerSentEvent.<Team>builder() | |
.data(team) | |
.build()); | |
return ServerResponse.ok().body(BodyInserters.fromServerSentEvents(sse)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment