Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any solution can send message to a group of user (not all user) using spring4 websocket?

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.

like image 323
Xiujun Ma Avatar asked Apr 11 '14 12:04

Xiujun Ma


People also ask

What is SimpMessagingTemplate?

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.

What is setApplicationDestinationPrefixes?

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.

What is enableStompBrokerRelay?

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.

What is WebSocket message broker?

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).


1 Answers

As of Spring Framework 4.0.x, it is possible to send messages to a group of users by:

  • explicitly sending messages to each user, using a for loop
  • sending messages to a particular topic, given those users subscribed to this topic beforehand.

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).

like image 129
Brian Clozel Avatar answered Oct 07 '22 12:10

Brian Clozel