I am trying to send and handle message from browser over STOPM using spring-messaging. But message is not sent.
Some code now:
@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");
}
}
As you can see i am using embedded springs simple broker.
<!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>
When i am trying to debug script part in firefox debug never reach part:
stomp.send('/app/marcopolo', {}, payload);
maybe stomp cannot connect?
stomp and sock objects are created properly.
@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());
}
}
When i call doSmth() function and try to breakpoint handleShout(Shout incoming) function i cannot catch that breakpoint. Function is never called.
Do you see what am i doing wrong?
ehh solution of that problem is really easy :) Just used wrong class to extend my WebSocketStompConfig. Used: AbstractSecurityWebSocketMessageBrokerConfigurer Should be: AbstractWebSocketMessageBrokerConfigurer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.