public class DefaultUserDestinationResolver extends Object implements UserDestinationResolver
UserDestinationResolver that relies
on the UserSessionRegistry
provided to the constructor to find the sessionIds associated with a user
and then uses the sessionId to make the target destination unique.
When a user attempts to subscribe to "/user/queue/position-updates", the "/user" prefix is removed and a unique suffix added, resulting in something like "/queue/position-updates-useri9oqdfzo" where the suffix is based on the user's session and ensures it does not collide with any other users attempting to subscribe to "/user/queue/position-updates".
When a message is sent to a user with a destination such as "/user/{username}/queue/position-updates", the "/user/{username}" prefix is removed and the suffix added, resulting in something like "/queue/position-updates-useri9oqdfzo".
| Constructor and Description |
|---|
DefaultUserDestinationResolver(UserSessionRegistry userSessionRegistry)
Create an instance that will access user session id information through
the provided registry.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkDestination(String destination,
String requiredPrefix) |
String |
getDestinationPrefix()
Return the prefix used to identify user destinations.
|
protected String |
getTargetDestination(String sourceDestination,
String sourceDestinationWithoutPrefix,
String sessionId,
String user)
This methods determines the translated destination to use based on the source
destination, the source destination with the user prefix removed, a session
id, and the user for the session (if known).
|
UserSessionRegistry |
getUserSessionRegistry()
Return the configured
UserSessionRegistry. |
UserDestinationResult |
resolveDestination(Message<?> message)
Resolve the destination of the message to a set of actual target destinations.
|
void |
setUserDestinationPrefix(String prefix)
The prefix used to identify user destinations.
|
String |
toString() |
public DefaultUserDestinationResolver(UserSessionRegistry userSessionRegistry)
userSessionRegistry - the registry, never nullpublic void setUserDestinationPrefix(String prefix)
The default value is "/user/".
prefix - the prefix to usepublic String getDestinationPrefix()
By default "/user/queue/".
public UserSessionRegistry getUserSessionRegistry()
UserSessionRegistry.public UserDestinationResult resolveDestination(Message<?> message)
UserDestinationResolverIf the message is SUBSCRIBE/UNSUBSCRIBE, the returned set will contain a single translated target destination.
If the message represents data being sent to a user, the returned set may contain multiple target destinations, one for each active user session.
resolveDestination in interface UserDestinationResolvermessage - the message with a user destination to be resolvednull if the resolution
fails (e.g. not a user destination, or no user info available, etc)protected String getTargetDestination(String sourceDestination, String sourceDestinationWithoutPrefix, String sessionId, String user)
sourceDestination - the source destination of the input messagesourceDestinationWithoutPrefix - the source destination without the user prefixsessionId - the id of the session for the target messageuser - the user associated with the session, or nullnull if none