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)
Return the target destination to use.
|
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.
|
public DefaultUserDestinationResolver(UserSessionRegistry userSessionRegistry)
userSessionRegistry
- the registry, never null
public 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)
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)protected String getTargetDestination(String sourceDestination, String sourceDestinationWithoutPrefix, String sessionId, 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