public class DefaultUserDestinationResolver extends java.lang.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".
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultUserDestinationResolver.DestinationInfo |
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
destinationPrefix |
private static Log |
logger |
private UserSessionRegistry |
userSessionRegistry |
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(java.lang.String destination,
java.lang.String requiredPrefix) |
java.lang.String |
getDestinationPrefix()
Return the prefix used to identify user destinations.
|
protected java.lang.String |
getTargetDestination(java.lang.String sourceDestination,
java.lang.String sourceDestinationWithoutPrefix,
java.lang.String sessionId,
java.lang.String user)
Return the target destination to use.
|
UserSessionRegistry |
getUserSessionRegistry()
Return the configured
UserSessionRegistry . |
private DefaultUserDestinationResolver.DestinationInfo |
parseUserDestination(SimpMessageHeaderAccessor headers) |
UserDestinationResult |
resolveDestination(Message<?> message)
Resolve the destination of the message to a set of actual target destinations.
|
void |
setUserDestinationPrefix(java.lang.String prefix)
The prefix used to identify user destinations.
|
private static final Log logger
private final UserSessionRegistry userSessionRegistry
private java.lang.String destinationPrefix
public DefaultUserDestinationResolver(UserSessionRegistry userSessionRegistry)
userSessionRegistry
- the registry, never null
public void setUserDestinationPrefix(java.lang.String prefix)
The default value is "/user/".
prefix
- the prefix to usepublic java.lang.String getDestinationPrefix()
By default "/user/queue/".
public UserSessionRegistry getUserSessionRegistry()
UserSessionRegistry
.public UserDestinationResult resolveDestination(Message<?> message)
UserDestinationResolver
If 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 UserDestinationResolver
message
- 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)private DefaultUserDestinationResolver.DestinationInfo parseUserDestination(SimpMessageHeaderAccessor headers)
protected boolean checkDestination(java.lang.String destination, java.lang.String requiredPrefix)
protected java.lang.String getTargetDestination(java.lang.String sourceDestination, java.lang.String sourceDestinationWithoutPrefix, java.lang.String sessionId, java.lang.String user)
sourceDestination
- the source destination from the input messagesourceDestinationWithoutPrefix
- the source destination with the target prefix removedsessionId
- an active user session iduser
- the user