Spring WebSocket 连接后不发送队列后缀 [英] Spring WebSocket is not send queue-suffix after connection
问题描述
我的服务器端配置在这里:
My server side config is here:
<websocket:message-broker application-destination-prefix="/chat">
<websocket:stomp-endpoint path="/connect">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/broadcast/"/>
</websocket:message-broker>
客户端代码:
var stompClient = null;
var socket = new SockJS('/connect');
stompClient = Stomp.over(socket);
stompClient.connect('', '', function (frame) {
console.log(frame); // Inside frame object queue-suffix not sended
var suffix = frame.headers['queue-suffix'];
stompClient.subscribe('/broadcast/message'+suffix, function(calResult){
console.log(calResult);
});
}, function (error) {
console.log(error);
});
连接成功,但在连接框架对象中找不到queue-suffix
Connection is successfully, but I can't find queue-suffix in connection frame object
推荐答案
我正在使用基于注解的配置和消息传递类.我也在使用 SpringBoot 1.2.0.RC1,它引入了 Spring 4.1.2.RELEASE.
I am using the annotation-based configs and messaging classes. I'm also using SpringBoot 1.2.0.RC1 which pulls in Spring 4.1.2.RELEASE.
所以,鉴于我设置了我的 websockets &STOMP 如下:
So, given that I set up my websockets & STOMP as follows:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketProdConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/inoutboard").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic", "/queue");
}
}
然后在我的控制器中发送/接收方法的一个例子是
and then an example of a send/receive method in my controller is
@Controller
public class InOutBoardController {
...
@MessageMapping("/user-status-refresh")
@SendToUser(value = "/queue/user-status-refresh", broadcast = false)
public UserStatusUpdateMessage[] userStatusRefresh() {
...
}
}
当我在客户端收到消息时,它们的主题是/user/njacobs5074/queue/user-status-values".
When I get my messages in the client, they have a topic of "/user/njacobs5074/queue/user-status-values".
希望这会有所帮助.
这篇关于Spring WebSocket 连接后不发送队列后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!