问题
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>
Client side code:
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);
});
Connection is successfully, but I can't find queue-suffix in connection frame object
回答1:
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.
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() {
...
}
}
When I get my messages in the client, they have a topic of "/user/njacobs5074/queue/user-status-values".
Hope this helps.
回答2:
We did include such a header in early milestones (up until 4.0 RC1 I think) but the "queue suffix" is now completed encapsulated on the server side. See the example from Nick above and also the docs Spring WebSocket is not send queue-suffix after connection.
来源:https://stackoverflow.com/questions/26991832/spring-websocket-is-not-send-queue-suffix-after-connection