Answer the question
In order to leave comments, you need to log in
How to return connection session ID in Spring + STOMP?
Hello, I need to get the SessionId when a socket connection occurs.
What SessionId are we talking about, what identifies the socket connection.
An example in which you can get this very SessionId
@MessageMapping("/find")
public void find(SimpMessageHeaderAccessor sha, User user) {
String sessionId = sha.getSessionId();
LOG.debug("New session id - {}, {}", sessionId, user);
// New session id - rs5ahsly, {user: Name, ...}
Repository.add(sessionId, user);
}
CONNECTED↵version:1.1↵heart-beat:0,0↵sessionId:rs5ahsly↵↵
public class CustomHandshakeHandler extends DefaultHandshakeHandler {
@Override
protected Principal determineUser(ServerHttpRequest request,
WebSocketHandler wsHandler,
Map<String, Object> attributes) {
return new StompPrincipal(UUID.randomUUID().toString());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question