Can't receive messages on client using SimpMessagingTemplate.convertAndSendToUser()

15 Views Asked by At

I'm trying to develop a simple private messaging application with spring boot. The messages sent from the client are properly received from the backend and persisted on the database, but the recipient can't receive them. There must be something with the endpoint the client is subscribed to.

This is the websocket broker configuration:

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
     config.enableSimpleBroker("/topic", "/queue");
     config.setApplicationDestinationPrefixes("/app");
     config.setUserDestinationPrefix("/user");
}

This is the controller that receives and sends the messages:


@Controller
public class MessagingController {
    @Autowired private SimpMessagingTemplate simpMessagingTemplate;
    @Autowired private ChatAndMessageService chatAndMessageService;

    @MessageMapping("/private")
    public void sendPrivateMessage(@Payload PrivateMessageDto msg) {
        PrivateChatMessage savedMsg=chatAndMessageService.save(msg);
        simpMessagingTemplate.convertAndSendToUser(msg.getRecipientUsername(), "/queue", savedMsg);
    }
}

And this is the client subscription. The idea is to make the user subscribe to an endpoint with its own surname, so that other users can send messages there.

this.rxStomp.watch("/user/" + this.user.username + "/queue").pipe(
      map(message => JSON.parse(message.body) as PrivateMessage)
);
0

There are 0 best solutions below