Please, give some hint regarding the following!
Pre-requisites:
- Mongo cluster of replica-set type
@EnableReactiveMongoRepositories
is in place and all the repositories extend fromReactiveMongoRepository
@EnableWebFluxSecurity
is in place, there is also a custom filter for Firebase authentication- Websocket connection is established from Flutter UI via SocketIO-type client (not a SockJS one)
I have a following flow (hereinafter i obfuscate the real classname with SomeClass
):
- SocketIO subscription from UI is done via
WebSocketHandler
implementation - it basically queries one object from Mongo given unique ID (only one item is expected). The code of handler method is pretty simple:
@Override
public Mono<Void> handle(org.springframework.web.reactive.socket.WebSocketSession session) {
return session.send(getUserId(session).flatMap(id -> service.findByUserId(id))
.map(item -> wrapResponse(item, session)));
}
Code within service class is also straightforward:
public Mono<SomeClass> findByUserId(String userId){
return repository.findSomeClassByUserId(userId);
}
- there is also a REST endpoint which i call with a PUT request to modify the object in the Mongo DB. The code of REST endpoint is pretty simple too:
@PutMapping("someclass")
public Mono<SomeClass> saveProfile(@RequestBody SomeClass payload){
return service.saveSomeClass(payload);
}
The question is:
- Is there any way how i can communicate the changes done in the REST call to the given object over the already established WebSocket session?
Considerations and assumptions:
- I was thinking about change streams - but it works better with SockJS
sendToUser
. Speaking about SocketIO - in this case there needs to be a registry of active sessions which really makes the profit of using reactive style miserable @Tailable
, as far as i understand, has a large limitation - only used for capped collections, which makes it impossible to use.
Guys, any advice and input is highly appreciated! Thank you so much in advance!