server config
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/ppdouble-websocket").withSockJS();
}
client connection
var socket = new SockJS('http://127.0.0.1:8080/ppdouble-websocket');
or
var socket = new SockJS('/ppdouble-websocket');
server config
registry a broker
registry.enableSimpleBroker("/ppdouble-topic");
controller: respond the subscription of client
@SendTo("/ppdouble-topic/user")
client subscribe
stompClient.subscribe('/ppdouble-topic/user"', function (greetingmessage){}
server config
registry.setApplicationDestinationPrefixes("/app");
controller: receive the request from client
@MessageMapping("/user")
client send message
stompClient.send("/app/user", {}, JSON.stringify({'name': $("#name").val()}));
default jar
packaging
<packaging>jar</packaging>
run and change server port by adding flag
java -jar target/springboot-websocket-message-0.0.1-SNAPSHOT.jar --server.port=8090 --trace
Using Spring Boot for WebSocket Implementation with STOMP
Spring Boot + Websocket Example