I would like to use Spring Messaging to create a real-time notification system for registered users for my web application.
I defined a AbstractWebSocketMessageBrokerConfigureras follows:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/notifications").withSockJS()
.setSessionCookieNeeded(true)
.setWebSocketEnabled(true);
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic/", "/queue/");
}
And according to the documentation:
An application can send messages intended for a specific user. Spring s STOMP support recognizes addresses, prefixes with "/ user /". For example, a client may subscribe to the destination "/ user / queue / position-updates". This destination will be handled by the UserDestinationMessageHandler and converted to a destination unique to the user session, for example. "/ Queue / outline-updates-user123". This provides the convenience of subscribing to a destination designated by name, while at the same time ensuring that there are no clashes with other users who have subscribed to the same destination, so that each user can receive unique position updates.
, "/user/{username}/queue/position-updates", , , UserDestinationMessageHandler , . , , - , . , .
/user/{username}/queue/something, , {username}.
, Message Broker (, RabbitMQ), Spring , :
registry.enableStompBrokerRelay("/topic/", "/queue/");
Spring:
- Message Broker,
/user/{username/}/queue/something? , ? - Message Broker,
/user/{username/}/queue/something, Spring {username} Principal?