我正在尝试使用spring-messaging通过STOPM从浏览器发送和处理消息。但不发送消息。
下面是一些代码:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketStompConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer{
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/marcopolo").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue", "/topic");
registry.setApplicationDestinationPrefixes("/app");
}
}如你所见,我使用的是嵌入式springs简单代理。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
<script th:src="@{/webjars/sockjs-client/1.0.2/sockjs.min.js}"/>
<script th:src="@{/webjars/stomp-websocket/2.3.3/stomp.min.js}"/>
<script>
function doSmth(){
var sock = new SockJS('/spittr/marcopolo');
var stomp = Stomp.over(sock);
var payload = JSON.stringify({'message': 'Marco !'});
stomp.connect('guest', 'guest', function(frame) {
stomp.send('/app/marcopolo', {}, payload);
});
var dupa = 'dupa';
}
</script>
</head>
<body>
<button onclick="doSmth();">Connect</button>
</body>
</html>当我尝试调试firefox中的脚本部分时,debug永远不会到达部分:
stomp.send('/app/marcopolo', {}, payload);也许stomp不能连接?
正确地创建了stomp和sock对象。
@Controller
public class MarcoController {
@RequestMapping(value = "/marcop", method = RequestMethod.GET)
public String getMarcoPolo(){
return "sockjstest";
}
@MessageMapping(value = "/marcopolo")
public void handleShout(Shout incoming){
System.out.println(incoming.getMessage());
}
}当我调用doSmth()函数并尝试对handleShout(Shout incoming)函数进行断点操作时,我无法捕获该断点。函数永远不会调用。
你知道我做错了什么吗?
发布于 2015-12-01 02:57:08
这个问题的解决方案非常简单:)只是使用了错误的类来扩展我的WebSocketStompConfig。Used: AbstractWebSocketMessageBrokerConfigurer应为:AbstractWebSocketMessageBrokerConfigurer
https://stackoverflow.com/questions/33985564
复制相似问题