0

Please, give some hint regarding the following!

Pre-requisites:

  • Mongo cluster of replica-set type
  • @EnableReactiveMongoRepositories is in place and all the repositories extend from ReactiveMongoRepository
  • @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!

3
  • Please dont describe your code, instead include enough code with a small example of what you want to establish, ask about. Voted to close, lack of debugging details. Commented Aug 9, 2021 at 14:19
  • @Toerktumlare, thank you for your response! Can you, please, be a bit more specific about "what you want to establish"? As i said: I want to make changes to an entity in database and want them to be propagated to the UI without using events/listening to anything etc. via reactor functionality. That's it more or less Commented Aug 10, 2021 at 9:09
  • @Toerktumlare, and yes - trying to describe the code i wanted to mitigate possible replies like - read the docs. I've read them but there is not much about particular usage of websockets (non-SockJS ones) and Spring Mongo Reactive - therefore, maybe someone might be having some relevant experience. I just wanted to give some context Commented Aug 10, 2021 at 9:14

1 Answer 1

0

The only way i have found so far is to use the change streams provided by Spring Data MongoDB

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.