如何从客户端出站通道访问 websocket 客户端入站通道拦截器中填充的 STOMP getSessionAttributes()?
How to access STOMP getSessionAttributes() that are populated in websocket client-inbound-channel interceptor from client-outbound-channel?
我正在使用 spring-websocket 并且我有这两个拦截器
<websocket:client-inbound-channel>
<websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
<websocket:interceptors>
<ref bean="myInterceptor"/>
</websocket:interceptors>
</websocket:client-inbound-channel>
<websocket:client-outbound-channel>
<websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
<websocket:interceptors>
<ref bean="myOutInterceptor"/>
</websocket:interceptors>
</websocket:client-outbound-channel>
我正在使用 StompHeaderAccessor 在两个拦截器中将消息包装在 preSend(Message<?> message, MessageChannel channel)
中。
我正在使用以下方法访问入站拦截器中的会话属性:
...
StompHeaderAccessor sha = StompHeaderAccessor.wrap(message);
// ignore non-STOMP messages like heartbeat messages
if(sha.getCommand() == null) {
return message;
}
String sessionId = sha.getSessionId();
Map<String, Object> sessionAttributes = sha.getSessionAttributes();
...
问题是,sha.getSessionAttributes();
在入站拦截器 returns 数据中,但是当我在出站拦截器中调用 sha.getSessionAttributes();
时,它 returns 为空。
如何从出站拦截器访问 sessionAttributes?
感觉像是一种解决方法。我就是这样解决的。
我添加了一个 bean,就像一个包含 Map 的存储库,键是会话 ID,值是会话属性。
在入站拦截器中,SUBSCRIBE 案例中,我将会话 ID 与属性放在一起。并在取消订阅和断开连接的情况下将其从地图中删除。
在出站拦截器中,case MESSAGE,我从那个 bean sessionAttributes = theBean.getSessionIdAndAttributes().get(sessionId)
中获取了相关的 sessionAttributes,而不是从消息对象中获取它 sessionAttributes = sha.getSessionAttributes()
。
我正在使用 spring-websocket 并且我有这两个拦截器
<websocket:client-inbound-channel>
<websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
<websocket:interceptors>
<ref bean="myInterceptor"/>
</websocket:interceptors>
</websocket:client-inbound-channel>
<websocket:client-outbound-channel>
<websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
<websocket:interceptors>
<ref bean="myOutInterceptor"/>
</websocket:interceptors>
</websocket:client-outbound-channel>
我正在使用 StompHeaderAccessor 在两个拦截器中将消息包装在 preSend(Message<?> message, MessageChannel channel)
中。
我正在使用以下方法访问入站拦截器中的会话属性:
...
StompHeaderAccessor sha = StompHeaderAccessor.wrap(message);
// ignore non-STOMP messages like heartbeat messages
if(sha.getCommand() == null) {
return message;
}
String sessionId = sha.getSessionId();
Map<String, Object> sessionAttributes = sha.getSessionAttributes();
...
问题是,sha.getSessionAttributes();
在入站拦截器 returns 数据中,但是当我在出站拦截器中调用 sha.getSessionAttributes();
时,它 returns 为空。
如何从出站拦截器访问 sessionAttributes?
感觉像是一种解决方法。我就是这样解决的。
我添加了一个 bean,就像一个包含 Map 的存储库,键是会话 ID,值是会话属性。
在入站拦截器中,SUBSCRIBE 案例中,我将会话 ID 与属性放在一起。并在取消订阅和断开连接的情况下将其从地图中删除。
在出站拦截器中,case MESSAGE,我从那个 bean sessionAttributes = theBean.getSessionIdAndAttributes().get(sessionId)
中获取了相关的 sessionAttributes,而不是从消息对象中获取它 sessionAttributes = sha.getSessionAttributes()
。