类 DefaultUserDestinationResolver
- java.lang.Object
- org.springframework.messaging.simp.user.DefaultUserDestinationResolver
- 所有已实现的接口:
UserDestinationResolver
public class DefaultUserDestinationResolver extends Object implements UserDestinationResolver
A default implementation ofUserDestinationResolver
that relies on aSimpUserRegistry
to find active sessions for a user.When a user attempts to subscribe, e.g. to "/user/queue/position-updates", the "/user" prefix is removed and a unique suffix added based on the session id, e.g. "/queue/position-updates-useri9oqdfzo" to ensure different users can subscribe to the same logical destination without colliding.
When sending to a user, e.g. "/user/{username}/queue/position-updates", the "/user/{username}" prefix is removed and a suffix based on active session id's is added, e.g. "/queue/position-updates-useri9oqdfzo".
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Brian Clozel
构造器概要
构造器 构造器 说明 DefaultUserDestinationResolver(SimpUserRegistry userRegistry)
Create an instance that will access user session id information through the provided registry.
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected boolean
checkDestination(String destination, String requiredPrefix)
String
getDestinationPrefix()
Return the configured prefix for user destinations.SimpUserRegistry
getSimpUserRegistry()
Return the configuredSimpUserRegistry
.protected String
getTargetDestination(String sourceDestination, String actualDestination, String sessionId, String user)
This method determines how to translate the source "user" destination to an actual target destination for the given active user session.boolean
isRemoveLeadingSlash()
Whether to remove the leading slash from target destinations.UserDestinationResult
resolveDestination(Message<?> message)
Resolve the given message with a user destination to one or more messages with actual destinations, one for each active user session.void
setPathMatcher(PathMatcher pathMatcher)
已过时。as of 4.3.14 this property is no longer used and is replaced bysetRemoveLeadingSlash(boolean)
that indicates more explicitly whether to keep the leading slash which may or may not be the case regardless of how thePathMatcher
is configured.void
setRemoveLeadingSlash(boolean remove)
Use this property to indicate whether the leading slash from translated user destinations should be removed or not.void
setUserDestinationPrefix(String prefix)
The prefix used to identify user destinations.String
toString()
构造器详细资料
DefaultUserDestinationResolver
public DefaultUserDestinationResolver(SimpUserRegistry userRegistry)
Create an instance that will access user session id information through the provided registry.- 参数:
userRegistry
- the registry, nevernull
方法详细资料
getSimpUserRegistry
public SimpUserRegistry getSimpUserRegistry()
Return the configuredSimpUserRegistry
.
setUserDestinationPrefix
public void setUserDestinationPrefix(String prefix)
The prefix used to identify user destinations. Any destinations that do not start with the given prefix are not be resolved.The default prefix is "/user/".
- 参数:
prefix
- the prefix to use
getDestinationPrefix
public String getDestinationPrefix()
Return the configured prefix for user destinations.
setRemoveLeadingSlash
public void setRemoveLeadingSlash(boolean remove)
Use this property to indicate whether the leading slash from translated user destinations should be removed or not. This depends on the destination prefixes the message broker is configured with.By default this is set to
false
, i.e. "do not change the target destination", althoughAbstractMessageBrokerConfiguration
may change that totrue
if the configured destinations do not have a leading slash.- 参数:
remove
- whether to remove the leading slash- 从以下版本开始:
- 4.3.14
isRemoveLeadingSlash
public boolean isRemoveLeadingSlash()
Whether to remove the leading slash from target destinations.- 从以下版本开始:
- 4.3.14
setPathMatcher
@Deprecated public void setPathMatcher(PathMatcher pathMatcher)
已过时。as of 4.3.14 this property is no longer used and is replaced bysetRemoveLeadingSlash(boolean)
that indicates more explicitly whether to keep the leading slash which may or may not be the case regardless of how thePathMatcher
is configured.Provide thePathMatcher
in use for working with destinations which in turn helps to determine whether the leading slash should be kept in actual destinations after removing theuserDestinationPrefix
.By default actual destinations have a leading slash, e.g.
/queue/position-updates
which makes sense with brokers that support destinations with slash as separator. When aPathMatcher
is provided that supports an alternative separator, then resulting destinations won't have a leading slash, e.g.jms.queue.position-updates
.- 参数:
pathMatcher
- the PathMatcher used to work with destinations- 从以下版本开始:
- 4.3
resolveDestination
public UserDestinationResult resolveDestination(Message<?> message)
从接口复制的说明:UserDestinationResolver
Resolve the given message with a user destination to one or more messages with actual destinations, one for each active user session.- 指定者:
resolveDestination
在接口中UserDestinationResolver
- 参数:
message
- the message to try to resolve- 返回:
- 0 or more target messages (one for each active session), or
null
if the source message does not contain a user destination.
checkDestination
protected boolean checkDestination(String destination, String requiredPrefix)
getTargetDestination
protected String getTargetDestination(String sourceDestination, String actualDestination, String sessionId, String user)
This method determines how to translate the source "user" destination to an actual target destination for the given active user session.- 参数:
sourceDestination
- the source destination from the input message.actualDestination
- a subset of the destination without any user prefix.sessionId
- the id of an active user session, nevernull
.user
- the target user, possiblynull
, e.g if not authenticated.- 返回:
- a target destination, or
null
if none