Recently, I use spring4 websocket to push message to end user.
I known that, there are 2 methods (convertAndSend
, convertAndSendToUser
) to send message in class SimpMessageSendingOperations .
But is there any way to send message to a group of user, and the user out of group cannot subscribe the message?
Thank you very much.
public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String> implements SimpMessageSendingOperations. An implementation of SimpMessageSendingOperations . Also provides methods for sending messages to a user. See UserDestinationResolver for more on user destinations.
setApplicationDestinationPrefixes("/app") - used to. Configure one or more prefixes to filter destinations targeting application annotated methods. When messages are processed, the matching prefix is removed from the destination in order to form the lookup path.
The enableStompBrokerRelay method returns a convenient Registration instance that exposes a fluent API. You can use this fluent API to configure your Broker relay: registry.
The MessageBroker WebSocket Subprotocol (MBWS) is a WebSocket Subprotocol used by messaging clients to send messages to, and receive messages from an internet message broker (herein called a message broker).
As of Spring Framework 4.0.x, it is possible to send messages to a group of users by:
As you mentioned, you don't want users that don't belong to that "group" to be able to subscribe to this topic. This calls, in fact, for authorization features.
With 4.0.x, security features are implemented at the HTTP level, for example during the HTTP Upgrade phase, before clients switch to websocket (see the websocket-portfolio application).
The feature you're asking for is implemented in Spring Security 4.0.0 (to be released, see this blog post for a full preview).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With