0

I'm using spring WebSocket and I don't know how to send messages to a specific partition that contains the username.

i.e.:

@MessageMapping("/getNotifications")
@SendTo("/topic/notifications")
public @ResponseBody List<NotificationResponse> getNotificationsWS(int size,
        SimpMessageHeaderAccessor headerAccessor, Principal principal) throws Exception {
    ActionResult<List<NotificationResponse>> notificationsAr;
    notificationsAr = this.listNotifications(size, principal);
    return notificationsAr.getResult();

}

I'm trying to send the messages to "/topic/notifications/myUserName" instead of "/topic/notifications". In this way each logged user consumes from his own partition.

How I can do it?

Pennywise83
  • 1,784
  • 5
  • 31
  • 44

1 Answers1

1

Try to inject SimpMessagingTemplate and then you can simpMessagingTemplate.convertAndSendToUser(username, "/queue/reply", message);

Take a look at Thanh post.

TOvidiu
  • 1,036
  • 11
  • 15