[英]Is it possible to send binary data with STOMP over WebSockets using Spring-WebSockets?
[英]Cannot send messages over stomp using Spring messaging
我正在尝试使用Spring消息通过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中调试脚本部分时,调试永远都不会达到目标:
stomp.send('/app/marcopolo', {}, payload);
也许脚无法连接?
正确创建了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传入)函数时,我无法捕获该断点。 函数从不调用。
你看到我在做什么错吗?
这个问题的解决方案真的很简单:)只是使用了错误的类来扩展我的WebSocketStompConfig。 使用的:AbstractSecurityWebSocketMessageBrokerConfigurer应该是:AbstractWebSocketMessageBrokerConfigurer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.