In my Spring Boot application I'm trying to implement a notifications functionality based on WebSockets.
I have provided a following configuration:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/notifications").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic", "/queue");
}
}
and trying to use SimpMessagingTemplate
in order to send a message from server side to a specific client(user).
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
public void sendMessages() {
simpMessagingTemplate.convertAndSendToUser(%user%, "/horray", "Hello, World!");
}
Right now I don't understand a few things:
What value should be used for
%user%
parameter ofsimpMessagingTemplate.convertAndSendToUser
method ?What is the correlation between my
/notifications
endpoint registered inWebSocketConfig.registerStompEndpoints
method anddestination
parameter ofsimpMessagingTemplate.convertAndSendToUser
method and how to properly use it?How to protect the users from reading other people's messages on the client ?